Using for loop

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

답변 (3개)

G A
G A 2012년 3월 9일

0 개 추천

EDITED
Class(:,i)= vlookup(MOD(1:end , 14:15),MOD(i,1),2,1);
Muhammad
Muhammad 2012년 3월 10일

0 개 추천

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

Muhammad
Muhammad 2012년 3월 10일
PS.
I have checked
vlookup(MOD(1:end , 14:15),MOD(1,1),2,1)
in the command window and it works fine for all values of i.
G A
G A 2012년 3월 10일
what is the size and type of output of vlookup()?
Walter Roberson
Walter Roberson 2012년 3월 10일
What is the error that it is showing?
Muhammad
Muhammad 2012년 3월 10일
@ G A
vlookup should give a single column array of 29441 rows (29441= length (b)also equal to length (MOD)
Muhammad
Muhammad 2012년 3월 10일
@ Walter Roberson
Error in ==> Cluster_treatment at 3
Class(i)= vlookup(MOD(1:end , 14:15),MOD(1327,1),2,1);
plz see code in question 1 .
G A
G A 2012년 3월 10일
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 2012년 3월 10일
"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?

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

Pramod Bhat
Pramod Bhat 2012년 3월 10일

0 개 추천

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

Muhammad
Muhammad 2012년 3월 10일
Hi Pramod
Thanks. I think i have tried same in answer 2. But its giving error.

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2012년 3월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by