problems with a for loop within a switch statement

I am creating a code where there is a for loop within a switch statement. I want the switch statement in there because I want to evaluate an expression, (SSIM), then for each time it is evaluated I want it to pick out values between 0 to 1 or from -1 to 1. But I am having trouble, and am not sure, how to set this up. Here is what I have so far:
ref = picture2
A = picture1
subplot(1,2,1); imshow(ref); title('Mode 1');
subplot(1,2,2); imshow(A); title('Mode 2');
fprintf('The SSIM value is %0.4f.\n',ssimval);
switch [ssimval, ssimmap] = ssim(A,ref);
case i := 1:
for i from 0 to 1 do
a := <i;
fprintf('The SSIM value is %0.4f.\n',ssimval);
figure, imshow(ssimmap,[]);
title(sprintf('ssim Index Map - Mean ssim Value is %0.4f,',ssimval));
otherwise
title(sprintf('ssim Index Map - Mean ssim Value is %0.4f does not fit within criteria,',ssimval));
end
Any suggestions? Thanks to all and to all a good night (except for the best Answerer :p) - Neo

 채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 29일
http://www.mathworks.com/help/matlab/ref/for.html (and notice you must end the loop)
I do not know what the intention is for your line
a := <i;
Perhaps you wanted assignment, but the "<i" part is a mystery. "<" looks like one of the relational operators but those require a value on each side of the symbol.

댓글 수: 6

Neo
Neo 2015년 7월 29일
Thank you for your response. My intention for that line is that I want all the values that are less than 1 that are between 0 and 1. The evaluative expression next to switch evaluates all the pictures I have loaded into it (Ref and A) these values are not just 0, 1, or -1 these values are also in BETWEEN 0 and 1. I was trying to get the first case to have a block statement that corresponded to the values between 0 and 1 hence the a := <i; where i went up up 1 (i := 1:). Which is why I needed the for loop within the switch statement. Thank you for reminding me to end the for loop.
a = i(i >=0 & i <= 1);
if what you want is to omit the values that are outside that range. If instead what you want is to set all the lower values to 0, and set all the higher values to 1, then use
a = min(max(i, 0), 1);
Neo
Neo 2015년 7월 29일
Thanks Walter I will install this and let you know how it runs. Also, how did you know to set a equal to that instead?
When you max() two values, you get the higher of the two values. So if you max() against 0 then any value less than 0 would be made 0. Likewise when you min() two values you get the smaller of the two values. So if you min() against 1 then any value greater than 1 would be made 1. You can then combine the two into a single call. max() against the lower bound, min() against the upper bound. It sounds reversed but it is what is needed.
Neo
Neo 2015년 7월 30일
I'm actually referring to the former a. That is what I wanted.
i(i >=0 & i <= 1) is an example of logical indexing. You define a test for the values you want to keep, resulting in a vector of true/false values. Indexing something with true and false selects the elements where the index is true.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

Neo
2015년 7월 28일

댓글:

2015년 7월 30일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by