Filter löschen
Filter löschen

Using for loop

4 Ansichten (letzte 30 Tage)
Muhammad
Muhammad am 9 Mär. 2012
Hi
I have written a simple code which goes like this;
for
i=1:length(b)
Class= vlookup(MOD(1:end , 14:15),MOD(i,1),2,1);
end
The problem is that Class only retains the last value (i.e. for the last value of b). I need to put all the values of class after it looks up for 1 = 1:length(b).
So my required answer should be an array with same dimensions as b.
Best regards

Antworten (3)

G A
G A am 9 Mär. 2012
EDITED
Class(:,i)= vlookup(MOD(1:end , 14:15),MOD(i,1),2,1);
  1 Kommentar
Muhammad
Muhammad am 10 Mär. 2012
Plz see below.

Melden Sie sich an, um zu kommentieren.


Muhammad
Muhammad am 10 Mär. 2012
Hi GA I have tried the
Class(i)= vlookup(MOD(1:end , 14:15),MOD(i,1),2,1);
however it gives error Error in ==> Cluster_treatment at 3
Complete statement that i am using is as
for i=1:length(MOD);
% Giving Met class to each match up
Class(i)= vlookup(MOD(1:end , 14:15),MOD(1327,1),2,1);
end
Best Regards
  7 Kommentare
G A
G A am 10 Mär. 2012
if vlookup() gives an column-array of length(b) in one cycle , then, perhaps, within the for-loop you have to try
Class(:,i)= vlookup()
See above edited
Walter Roberson
Walter Roberson am 10 Mär. 2012
"Error in ==> Cluster_treatment at 3" says where the error _is_, but does not say what the error is. For example is it complaining that the number of dimensions in the left hand side must match the number of dimensions in the right hand side?

Melden Sie sich an, um zu kommentieren.


Pramod Bhat
Pramod Bhat am 10 Mär. 2012
hai. you try saving the value of class in an array, so that each time loop runs it will be automatically saved in that.
  1 Kommentar
Muhammad
Muhammad am 10 Mär. 2012
Hi Pramod
Thanks. I think i have tried same in answer 2. But its giving error.

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by