How to make one matrix?

2 ビュー (過去 30 日間)
Ahmed
Ahmed 2024 年 1 月 28 日
コメント済み: Walter Roberson 2024 年 1 月 29 日
Hi
I have 100 arrays i.e. each have one row and diffrent columns (say size is A = 1 * 167 and B = 1 * 189 and so on). I want to make one matrix in way that the first row is A, second row is B and so on... But the columns will remain different. How can I do it?
  4 件のコメント
Ahmed
Ahmed 2024 年 1 月 29 日
@Torsten No this is not working e.g.,
ITER = [iters_1; iters_2];
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in PLOTTING_UNCERTINITY (line 172)
ITER = [iters_1; iters_2];

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

採用された回答

Torsten
Torsten 2024 年 1 月 28 日
移動済み: Torsten 2024 年 1 月 28 日
Either use a cell array or dimension the matrix to have the maximum number of columns of the 100 row vectors:
A = [1 23 45];
B = [1 2];
M1 = cell(2,1);
M1{1} = A;
M1{2} = B;
M1
M1 = 2×1 cell array
{[1 23 45]} {[ 1 2]}
n = max(size(A,2),size(B,2));
M2 = zeros(2,n);
M2(1,:) = [A,zeros(1,n-size(A,2))];
M2(2,:) = [B,zeros(1,n-size(B,2))];
M2
M2 = 2×3
1 23 45 1 2 0
  5 件のコメント
Stephen23
Stephen23 2024 年 1 月 29 日
編集済み: Stephen23 2024 年 1 月 29 日
"How to get rid off these zeros during plotting?"
Replace ZEROS with NAN. Or use the approach I gave you here:
"actually all the variables are stored separetly."
Having lots of separate variables makes your data much harder to work with.
It is much better to use a cell array or structure array.
Walter Roberson
Walter Roberson 2024 年 1 月 29 日
Whatever process is loading all that data into seperate variables: it would be better if it loaded it all into a cell or a struct array to start with.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by