For loop in matlab

  • MATLAB
  • Thread starter jaclyn89
  • Start date
  • #1
5
0
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
 

Answers and Replies

  • #2
Pythagorean
Gold Member
4,214
272
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.
 
  • #3
5
0
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.
 
  • #4
Pythagorean
Gold Member
4,214
272
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.
 

Related Threads on For loop in matlab

Replies
1
Views
3K
Replies
1
Views
2K
Replies
4
Views
6K
Replies
4
Views
10K
  • Last Post
Replies
5
Views
3K
  • Last Post
Replies
1
Views
643
  • Last Post
Replies
10
Views
16K
Replies
2
Views
28K
Replies
2
Views
2K
Replies
2
Views
2K
Top