How to get column function result into separate variables?

What I mean is you can do:
A=rand(2);
[a,b]=size(A);
But is it possible to do something like:
A=rand(2);
[a;b]=size(A)';

1 件のコメント

Stephen23
Stephen23 2018 年 10 月 14 日
編集済み: Stephen23 2018 年 10 月 14 日
"How to get column function result into separate variables?"
The question is not clear. The output of size as you are using it with two output arguments is NOT one "vector", it is two output arguments which have absolutely no dimensional/positional/... relationship with each other. Definitely NOT one "vector" or array as you seem to assume:
[a,b]=size(A);
^^^^^ This is NOT a row vector!

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

回答 (2 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 10 月 14 日
編集済み: KALYAN ACHARJYA 2018 年 10 月 14 日

0 投票

But is it possible to do something like:
No, size(X) returns the row vector [1 1].
A=rand(2);
[a;b]=size(A)';
If you tried this one [a;b], it is vector [2,1]
This see the example, you can do this one, this way
>> [a b]=size(A);
>> t=[a b]'
t =
2
2
[m,n]=size(X) returns the size of matrix X in separate variables m and n, here you can use the intermediates variables.
What you have tried, get the size, it must be stored in variables [a;b], if you directly tried another function (transpose) without store it, how can you do that.
--------
A=rand(2);
[a b]=size(A');

4 件のコメント

Pawel Cembaluk
Pawel Cembaluk 2018 年 10 月 14 日
Maybe size() wasn't best example here. How to deal with this one:
A=rand(2);
B=rand(2,1);
[x;y]=A*B; %incorrect
madhan ravi
madhan ravi 2018 年 10 月 14 日
What you want to do exactly?
Pawel Cembaluk
Pawel Cembaluk 2018 年 10 月 14 日
I'm just curious if it is possible to get x and y like in this example without creating additional temporary variables (and also I don't want to replace [x;y] with a single vector).
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 10 月 14 日
編集済み: KALYAN ACHARJYA 2018 年 10 月 14 日
Check with whos, I found a very important question, Thanks for the question, learning for me also
>> A=rand(2);
B=rand(2,1);
>> C=A*B;
>> y=[6;7];
>> whos
Name Size Bytes Class Attributes
A 2x2 32 double
B 2x1 16 double
C 2x1 16 double
y 2x1 16 double

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

Walter Roberson
Walter Roberson 2018 年 10 月 14 日

0 投票

You should have a look at deal() -- though if you do not use a temporary variable then it helps to use an auxiliary function
expand_cell = @(C) C{:};
[x, y] = expand_cell( num2cell( A* B) );

カテゴリ

ヘルプ センター および File ExchangeVehicle Dynamics Blockset についてさらに検索

製品

リリース

R2018b

タグ

質問済み:

2018 年 10 月 14 日

編集済み:

2018 年 10 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by