필터 지우기
필터 지우기

Same loop have different vector output

조회 수: 2 (최근 30일)
Chaudhary P Patel
Chaudhary P Patel 2022년 4월 13일
댓글: Chaudhary P Patel 2022년 4월 15일
Sir, when i am running this loop for f_s the first f_s1 is comming as a column vector while f_s2, 3, 4, 5, are comming as a row vector.
Please sir, suggest me where i amking the mistakes.
utdelt=([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15]);
Ktts=rand(6,6);
for i=1:1:10
for n=1:1:5
if n==1
Utdelt=([zeros(3,1); (utdelt(1:3,i))]);
eval(['Utdelt',num2str(n),'=[zeros(3,1); (utdelt(1:3,i))]']);
else
Utdelt=utdelt([((1+(n-2)*3):(6+(n-2)*3)),i]);
eval(['Utdelt',num2str(n),'=[utdelt((1+(n-2)*3):(6+(n-2)*3,i)]']);
end
eval(['Ktts',num2str(n),'l']);
eval(['f_s',num2str(n),'=Ktts*Utdelt']);
end
end
  댓글 수: 4
Chaudhary P Patel
Chaudhary P Patel 2022년 4월 13일
@Walter Roberson sir, detailed problem it is there.
sir, problem is coming in this line, because f_s2, 3, 4,5 is coming as a row vector and the Utdelt value also not taking properly. So suggest me about this line.
eval(['f_s',num2str(n),'=Ktts*Utdelt']);
Stephen23
Stephen23 2022년 4월 13일
편집: Stephen23 2022년 4월 13일
"Please sir, suggest me where i amking the mistakes."
The obvious mistake is that you are forcing meta-data into variable names.
That forces you into writing slow, complex, inefficient, obfuscated, buggy code that is hard to debug (which is exactly what your question demonstrates, and hopefully you are about to start to notice).

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

채택된 답변

Walter Roberson
Walter Roberson 2022년 4월 13일
  댓글 수: 7
Walter Roberson
Walter Roberson 2022년 4월 14일
When you do not post actual code, then we cannot give you actual answers.
For the code that you posted the bug is that Ktts1l is not defined.
Chaudhary P Patel
Chaudhary P Patel 2022년 4월 15일
@Walter Roberson sir, just tell me is it correct? if wrong please correct me.
utdelt=([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15]);
nodof=3;
for i=1
for n=1:1:5
if n==1
Utdelt=([zeros(nodof,1); (utdelt(1:nodof,i))]);
eval(['Utdelt',num2str(n),'=[zeros(nodof,1); (utdelt(1:nodof,i))]']);
else
Utdelt=utdelt([(1+(n-2)*nodof):(6+(n-2)*nodof),(i)]);
eval(['Utdelt',num2str(n),'=[utdelt([(1+(n-2)*nodof):(6+(n-2)*nodof,(i)])]']);
end
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by