C=[ ];
for A=1:4
B=[5 10 5 10];
end
C=[A,B]
for example :
A=1:4
and
B=[5 10 5 10]
if A==1 & 3 then B==5, and when A==2&4 B==10
A B
1 5
2 10
3 5
4 10
How we could use Matlab code to obtain the above loop as shown in the picture, Thank you in advance for your assistance,

 採用された回答

Amit
Amit 2014 年 1 月 18 日
編集済み: Amit 2014 年 1 月 18 日

0 投票

I think simple doing
C = [A' B'];
would work. You dont need to do this in a loop.

5 件のコメント

UTS
UTS 2014 年 1 月 18 日
編集済み: UTS 2014 年 1 月 18 日
WOW, Thank you for your prompt reply. However, I got error as:
Error using horzcat Dimensions of matrices being concatenated are not consistent.
Error in checkthis (line 8) C = [A' B']
Amit
Amit 2014 年 1 月 18 日
Well in simple terms, in [X Y], both X and Y should be column matrix (nx1) When I wrote [A' B'], I assumed both A and B being row vector as A = 1:4, create a row matrix and B = [5 10 5 10] creates a row matrix. If this changed any how in your code, you have to modify C = [A' B'] accordingly.
Do me a favor and post the result for size(A) and size(B) before you do C = [A' B']
UTS
UTS 2014 年 1 月 18 日
Thank you very much, I tried to do this
B=[5 10 5 10];
A=[]; C=[B,A]
for A=1:4
B=[5 10 5 10];
size(A);
size(B) ;
C=[A';B']
end
The answer as:
C =
1
5
10
5
10
C =
2
5
10
5
10
C =
3
5
10
5
10
C =
4
5
10
5
10
Amit
Amit 2014 年 1 月 18 日
編集済み: Amit 2014 年 1 月 18 日
Okay, that's the problem.
What I said was to do is:
B = [5,10,5,10];
A = 1:4;
C = [A' B'];
Than simple. No loops, nothing.
UTS
UTS 2014 年 1 月 18 日
Thank you very much C =
1 5
2 10
3 5
4 10

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

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

UTS
2014 年 1 月 18 日

コメント済み:

UTS
2014 年 1 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by