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 commentaires

@KSSV please suggest me where i am doing wrong for that f_s is coming as a row vector for n=2,3,4,5.
eval(['Ktts',num2str(n),'l']);
You have not supplied any function named Ktts1l and have not assigned to a variable of that name.
@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 le 13 Avr 2022
Modifié(e) : Stephen23 le 13 Avr 2022
"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).

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 13 Avr 2022

0 votes

7 commentaires

means what sir?
Stephen23
Stephen23 le 13 Avr 2022
"means what sir?"
Use an actual index rather than forcing a pseudo-index into the variable names.
I had to leave in the eval() because as I indicated earlier, your code breaks there because you have not defined any Ktts1l variable or function, so I have no idea what you intended by that statement.
num_i = 10;
num_n = 5;
utdelt = ([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15]);
Ktts = rand(6,6);
for i = 1:num_i
Utdelt = cell(num_n,1);
f_s = cell(num_n,1);
for n = 1 : num_n
if n==1
Utdelt{n} = [zeros(3,1); utdelt(1:3,i)];
else
Utdelt{n} = utdelt((1+(n-2)*3):(6+(n-2)*3), i);
end
eval(['Ktts',num2str(n),'l']);
f_s{n} = Ktts * Utdelt{n}
end
end
Error using eval
Unrecognized function or variable 'Ktts1l'.
Notice that you overwrite all of the Utdelt and f_s entries each time through the for n loop, which is inside the for i loop. The end result in Utdelt and f_s is going to reflect only the result in the last iteration of i when i = 10. You should be considering whether one of your outputs should be indexed by i .
@Walter Roberson Sir, as fa as Ktts1l is concerned, that is in my code, for showing here i have to write full code to show here. That is absolutly right. Just sir, i do not understant that for n=1, f_s1 is coming as a column vector while for the rest of the n, it is coming as row vector.
@Walter Roberson sir, anything wrong in loop of n and i?
Walter Roberson
Walter Roberson le 14 Avr 2022
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.
@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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Produits

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by