b=[1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
a=zeros(3,1);
c=([a;b]);
d=(c(1,1):c(6,1));
e=(c(4,1):c(9,1));
please suggest me the way how can i write the code for vector d and e.
i want d vector as; d= [0;0;0;1;2;3] and
vector e as ; e=[1;2;3;4;5;6]

 採用された回答

Voss
Voss 2022 年 4 月 8 日

0 投票

b = [1;2;3;4;5;6;7;8;9;10;11;12;13;14;15];
a = zeros(3,1);
c = [a; b]
c = 18×1
0 0 0 1 2 3 4 5 6 7
d = c(1:6,1) % ",1" not necessary since c only has one column
d = 6×1
0 0 0 1 2 3
e = c(4:9) % ",1" omitted
e = 6×1
1 2 3 4 5 6

8 件のコメント

Chaudhary P Patel
Chaudhary P Patel 2022 年 4 月 8 日
Thanks Sir,
Voss
Voss 2022 年 4 月 8 日
You're welcome!
Chaudhary P Patel
Chaudhary P Patel 2022 年 4 月 15 日
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
Voss
Voss 2022 年 4 月 15 日
編集済み: Voss 2022 年 4 月 15 日
I can't say whether it's correct since I don't know what it's supposed to do, but I would make Utdelt a matrix:
utdelt=([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15]);
nodof=3;
Utdelt = zeros(6,5);
for i=1
for n=1:1:5
if n==1
Utdelt(:,n) = [zeros(nodof,1); utdelt(1:nodof,i)];
else
Utdelt(:,n) = utdelt( 1+(n-2)*nodof : 6+(n-2)*nodof , i );
end
end
end
Utdelt
Utdelt = 6×5
0 1 4 7 10 0 2 5 8 11 0 3 6 9 12 1 4 7 10 13 2 5 8 11 14 3 6 9 12 15
Chaudhary P Patel
Chaudhary P Patel 2022 年 4 月 15 日
sir i want to extract Utdelt as a column vector of 6X1.
Voss
Voss 2022 年 4 月 15 日
But you calculate Utdelt in a loop that iterates 5 times.
If you want each Utdelt as a 6x1 column vector then how you had it was basically fine. Here is your code again, except without the eval statements, without all the unnecessary parentheses, fixing the indentation, and adding a missing end at the end.
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)];
else
Utdelt = utdelt( 1+(n-2)*nodof : 6+(n-2)*nodof , i );
end
Utdelt
% presumably, you would do something with Utdelt at this point
end
end
Utdelt = 6×1
0 0 0 1 2 3
Utdelt = 6×1
1 2 3 4 5 6
Utdelt = 6×1
4 5 6 7 8 9
Utdelt = 6×1
7 8 9 10 11 12
Utdelt = 6×1
10 11 12 13 14 15
Chaudhary P Patel
Chaudhary P Patel 2022 年 4 月 15 日
thank you sir, in this loop i am calculating the f_s but when i am seeing the result the output is comin wrong.
utdelt=([1;2;3;4;5;6;7;8;9;10;11;12;13;14;15]);
Ktts=rand(6,6);
nodof=3;
for i=1
for n=1:1:5
if n==1
Utdelt = [zeros(nodof,1); utdelt(1:nodof,i)];
else
Utdelt = utdelt( 1+(n-2)*nodof : 6+(n-2)*nodof , i );
end
Utdelt
% presumably, you would do something with Utdelt at this point
end
f_s=Ktts*Utdelt;
end
Voss
Voss 2022 年 4 月 15 日
That uses the value of Utdelt that was calculated for n=5. Previously calculated Utdelt values, i.e., for n=1 through n=4, are not used. Maybe that's what's wrong.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2022 年 4 月 8 日

コメント済み:

2022 年 4 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by