PDA

View Full Version : for loop in matlab


jaclyn89
Jan15-12, 10:48 AM
hi, i am facing some problem in my for loop or ifesle statement in matlab.
i used a for loop to load the images from a folder, after the images loaded, it will gone through some calculation to get the average. if the images average <=10, then i want to display the images name in a listbox. let say i have 10 images in my folder, and average for images' 2,4 and 6 is <=10, the images will still go through else statement. if the average of last image is <=10, it just will stop in if statement and wont go through else statement. anyone know what is the problem?

here is some part of my code:

sdirectory = 'D:\recognition system\database'; %specific the file directory
filess = dir([sdirectory '/*.png']);
for k = 1:length(filess)
filename = [sdirectory '\' filess(k).name];
I = imread(filename);

....
aveg(k)=abs((standev/mean1)*100);

if( aveg(k)<= 10 )


lo{k}=sprintf('%% of diffrence for <<%s>> is %G %%\n\n ',filename,aveg(k));
set(handles.listbox1,'String',lo);

else

set(handles.listbox1,'String','');
end
end

Pythagorean
Jan15-12, 02:19 PM
Not sure if you're saying you get an error. If you do, post it.

If you don't, try removing the ; for aveg(k) value so that it will output the value during run (or just add the line disp(aveg(k)) and confirm you're getting the numbers you expect.

jaclyn89
Jan16-12, 01:59 AM
Not sure if you're saying you get an error. If you do, post it.

If you don't, try removing the ; for aveg(k) value so that it will output the value during run (or just add the line disp(aveg(k)) and confirm you're getting the numbers you expect.


thank you for ur reply:)

there is no error. if i add disp(aveg(k),the output is show in workplace but not my gui listbox. my problem not the display output problem. my problem is if the last images that loaded from folder is not my expected output, then it will continue to else statement even the first few images is my expected output.

i used if else statement is wan to filter out the expect image and non-expect image.eg:if i loaded 10images, the first 4 images is my expect output, then it should not go through else statement;but now it will run the else statement too.

Pythagorean
Jan16-12, 02:12 AM
I don't comprehend what you're saying, still, I don't know what you're trying to do. And it's hard to troubleshoot your code when you leave gaps in it.

The reason I had you display that is because it's the variable that your IF line depends on... this is just a step to debug code, not a fix. You would remove the disp after you work out the logic of what your loop is doing.

you might want to put disp('true') in the if section so that you know which ones go through the if and which ones don't.

But remember, this is just so that YOU can debug. I still have no idea what you're doing.