How to use loops to compare values?

4 Ansichten (letzte 30 Tage)
Yao
Yao am 11 Okt. 2012
Hi all,
I have a set of 20 values that I need to compare with a certain value. How do I use the for loop to compare the values with writing code 20 times?
Thank you
This is what I have done so far:
I have values stored from DiffQ1 to DiffQ20 I need to compare the values Difference = 600 Results = 0
if DiffQ1 > Difference
Results = Results + 0
else
Results = Results + 1
end;
to
if DiffQ20 > Difference
Results = Results + 0
else
Results = Results + 1
end

Antworten (2)

Jan
Jan am 11 Okt. 2012
Store the set of values in a cell array instead of hiding the index in the names:
DiffQ = cell(1, 20);
DiffQ{1} = ...
DiffQ{2} = ...
for ii = 1:20
... your operations with DiffQ{ii} here, e.g.:
disp(DiffQ{ii})
end
  1 Kommentar
Yao
Yao am 11 Okt. 2012
Hi Sir,
I got this error message.
DiffQ(1) = AreaSampleQ1 - AreaStudentQ1;
??? Conversion to cell from double is not possible.
How do I store the value in a cell array?
Thank you

Melden Sie sich an, um zu kommentieren.


Sachin Ganjare
Sachin Ganjare am 11 Okt. 2012

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by