I have got three vectors a, b and c with lengths 20 ,14,9, respectively.(20 elements, 14 elements and 9 elements). Now for all three vectors I am using for loop where X shall be such that X for first initiation gets vector a, for second gets b and for third iteration gets c. How can it be done? Please guide

回答 (2 件)

KSSV
KSSV 2020 年 12 月 25 日

0 投票

X = zeros(1,3) ;
X(1) = a ;
X(2) = b ;
X(3) = c ;
You need not to use, a loop..while initiating itself initiate it as avector.
X = [20 14 9] ;

1 件のコメント

Fazal Muhammad Ali Khan
Fazal Muhammad Ali Khan 2020 年 12 月 25 日
Yes in this case I have only three vectors which would be stretched to 10. Besides that, value of a is not 20 its range is 20 i.e a random vector with length 20. Same goes for b and c.

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

Image Analyst
Image Analyst 2020 年 12 月 25 日
編集済み: Image Analyst 2020 年 12 月 25 日

0 投票

What is "initiation"? And what is X?
How many loops are you expecting -- one or three?
If this what you mean?
for k = a
% do something.
end
for k = b
% do something.
end
for k = c
% do something.
end
Please post your actual numerical example but only AFTER you read the posting guidelines again:

カテゴリ

質問済み:

2020 年 12 月 25 日

編集済み:

2020 年 12 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by