how to combine these in an array

5 ビュー (過去 30 日間)
ALDO
ALDO 2020 年 4 月 29 日
コメント済み: Adam Danz 2020 年 4 月 29 日
Hi
I have 4 variables with type duration. for example they have sizes a=1x2 duration b=0x1 duration c=0x1duration, d=1x20 duration (not always these sizes). How can i put them in an array or matrix then sort them.
I tried A=sort([a;b;c;d])
but I get the error
Error using duration/horzcat (line 612)
Dimensions of arrays being concatenated are not consistent.
I would appriciate any suggestions
Thanks in advance!

採用された回答

Guillaume
Guillaume 2020 年 4 月 29 日
You're trying to vertically concatenate arrays with different number of columns (2, 1, 1, and 20), which indeed is not possible and makes no sense.
You wouldn't be able to horizontally concatenate them either since they also have a different number of rows (1, 0, 0, and 1).
If you really need to concatenate them into something you 'll have to reshape them to at least one common dimension which is likely a vector:
sort([a(:); b(:); c(:); d(:)])
whether or not it makes sense to reshape them into vectors, only you knows.
On the other hand, if you should have been able to vertically concatenate the vectors in the first place, then something has gone wrong in the code before that and you'll have to explain how these array came to be if you want more help.
  2 件のコメント
ALDO
ALDO 2020 年 4 月 29 日
That worked perfectly! Thank you for your explanation
Adam Danz
Adam Danz 2020 年 4 月 29 日
Why can't they be horizontally concatenated?
a = rand(1,2);
b = rand(0,1);
c = rand(0,1);
d = rand(1,120);
z = [a,b,c,d]
result
>> size(z)
ans =
1 122
>> z
z =
Columns 1 through 10
0.50382 0.20128 0.53055 ....

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by