How to use a function like reshape but for indivisible parameters?

1 回表示 (過去 30 日間)
Aaron
Aaron 2024 年 6 月 4 日
回答済み: Voss 2024 年 6 月 4 日
I am trying to compare two different sets of data containing ozone concentrations, one set I have collected, the other set has been collected by a third party. I have 64 data points and the third party has 12. How can I use a function like reshape to account for the data sets being indivisible between each other?
Flight1O3 = Aug2Flight1.O3_ppb(:); % the column with 64 data entries
Alt_O3 = reshape(Flight1O3, [], 12); % trying to reshape the 64 into 12

回答 (1 件)

Voss
Voss 2024 年 6 月 4 日
You'll have to put some additional elements in the vector for the reshape operation to work:
A = rand(68,1);
N = ceil(numel(A)/12)*12; % next multiple of 12
A(end+1:N) = NaN; % extend A with NaNs to size N
A_new = reshape(A,[],12);
disp(A_new)
0.2416 0.7705 0.7404 0.9881 0.7055 0.3564 0.7440 0.3907 0.1715 0.0664 0.0051 0.6725 0.4309 0.4235 0.3445 0.4761 0.7249 0.0805 0.4457 0.7846 0.3759 0.1771 0.9608 0.2251 0.1951 0.8048 0.5579 0.8783 0.0815 0.6057 0.8640 0.7410 0.7466 0.3297 0.3103 NaN 0.5070 0.8626 0.3019 0.2127 0.5446 0.5728 0.7612 0.4972 0.7465 0.0378 0.1313 NaN 0.3798 0.2026 0.2644 0.2006 0.0587 0.0296 0.7764 0.5126 0.9105 0.9769 0.4389 NaN 0.5558 0.0182 0.1631 0.0883 0.6959 0.7703 0.2238 0.5011 0.0872 0.7769 0.1082 NaN
If you have R2023b or newer you can use the resize function to do that:
A = resize(A,N,'FillValue',NaN); % extend A with NaNs to size N
A_new = reshape(A,[],12);
disp(A_new)
0.2416 0.7705 0.7404 0.9881 0.7055 0.3564 0.7440 0.3907 0.1715 0.0664 0.0051 0.6725 0.4309 0.4235 0.3445 0.4761 0.7249 0.0805 0.4457 0.7846 0.3759 0.1771 0.9608 0.2251 0.1951 0.8048 0.5579 0.8783 0.0815 0.6057 0.8640 0.7410 0.7466 0.3297 0.3103 NaN 0.5070 0.8626 0.3019 0.2127 0.5446 0.5728 0.7612 0.4972 0.7465 0.0378 0.1313 NaN 0.3798 0.2026 0.2644 0.2006 0.0587 0.0296 0.7764 0.5126 0.9105 0.9769 0.4389 NaN 0.5558 0.0182 0.1631 0.0883 0.6959 0.7703 0.2238 0.5011 0.0872 0.7769 0.1082 NaN

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by