How do I add a column of zeros to the end of a matrix inside a cell?

3 ビュー (過去 30 日間)
lil brain
lil brain 2022 年 2 月 26 日
コメント済み: lil brain 2022 年 2 月 27 日
Hello,
I have the cell "basket_xyz" and I would like balls_xyz{:,10} to only be zeros for the entire column or for the same length as all other columns.
I have tried using:
baskets_xyz{:,10} = zeros(length(baskets_xyz{:,9}, 1)
But it doesnt work.
What am I doing wrong?
Thanks!
  2 件のコメント
Stephen23
Stephen23 2022 年 2 月 27 日
Is there a particular reason why you are inefficiently storing lots of scalar numeric in a cell array, thus making it more difficult to process that numeric data? Why not just use one simple, efficient, numeric array?
S = load('baskets_xyz.mat')
S = struct with fields:
baskets_xyz: {979×9 cell}
M = cell2mat(S.baskets_xyz)
M = 979×9
-2.2972 1.4684 -0.9453 -2.2405 0.9547 -0.8059 -2.0906 0.8165 -0.8956 -2.2958 1.4681 -0.9451 -2.2412 0.9534 -0.8077 -2.0943 0.8144 -0.8944 -2.2934 1.4682 -0.9449 -2.2418 0.9517 -0.8113 -2.0991 0.8112 -0.8916 -2.2934 1.4682 -0.9449 -2.2425 0.9507 -0.8129 -2.1019 0.8092 -0.8905 -2.2923 1.4684 -0.9448 -2.2418 0.9512 -0.8130 -2.0995 0.8104 -0.8907 -2.2923 1.4684 -0.9448 -2.2422 0.9504 -0.8144 -2.1019 0.8087 -0.8898 -2.2912 1.4685 -0.9444 -2.2416 0.9508 -0.8141 -2.1000 0.8095 -0.8902 -2.2890 1.4683 -0.9440 -2.2415 0.9539 -0.8127 -2.0979 0.8090 -0.8904 -2.2890 1.4683 -0.9440 -2.2418 0.9548 -0.8124 -2.0980 0.8084 -0.8902 -2.2880 1.4684 -0.9440 -2.2422 0.9563 -0.8108 -2.0971 0.8088 -0.8907
M(:,end+1) = 0
M = 979×10
-2.2972 1.4684 -0.9453 -2.2405 0.9547 -0.8059 -2.0906 0.8165 -0.8956 0 -2.2958 1.4681 -0.9451 -2.2412 0.9534 -0.8077 -2.0943 0.8144 -0.8944 0 -2.2934 1.4682 -0.9449 -2.2418 0.9517 -0.8113 -2.0991 0.8112 -0.8916 0 -2.2934 1.4682 -0.9449 -2.2425 0.9507 -0.8129 -2.1019 0.8092 -0.8905 0 -2.2923 1.4684 -0.9448 -2.2418 0.9512 -0.8130 -2.0995 0.8104 -0.8907 0 -2.2923 1.4684 -0.9448 -2.2422 0.9504 -0.8144 -2.1019 0.8087 -0.8898 0 -2.2912 1.4685 -0.9444 -2.2416 0.9508 -0.8141 -2.1000 0.8095 -0.8902 0 -2.2890 1.4683 -0.9440 -2.2415 0.9539 -0.8127 -2.0979 0.8090 -0.8904 0 -2.2890 1.4683 -0.9440 -2.2418 0.9548 -0.8124 -2.0980 0.8084 -0.8902 0 -2.2880 1.4684 -0.9440 -2.2422 0.9563 -0.8108 -2.0971 0.8088 -0.8907 0
lil brain
lil brain 2022 年 2 月 27 日
Hi Steven, Actually there is no reason. Thanks or your comment. I think this is actually better. I was already wondering why this takes so long!

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

採用された回答

Voss
Voss 2022 年 2 月 26 日
Maybe this?
load('baskets_xyz.mat')
baskets_xyz(:,10) = {0}
baskets_xyz = 979×10 cell array
{[-2.2972]} {[1.4684]} {[-0.9453]} {[-2.2405]} {[0.9547]} {[-0.8059]} {[-2.0906]} {[0.8165]} {[-0.8956]} {[0]} {[-2.2958]} {[1.4681]} {[-0.9451]} {[-2.2412]} {[0.9534]} {[-0.8077]} {[-2.0943]} {[0.8144]} {[-0.8944]} {[0]} {[-2.2934]} {[1.4682]} {[-0.9449]} {[-2.2418]} {[0.9517]} {[-0.8113]} {[-2.0991]} {[0.8112]} {[-0.8916]} {[0]} {[-2.2934]} {[1.4682]} {[-0.9449]} {[-2.2425]} {[0.9507]} {[-0.8129]} {[-2.1019]} {[0.8092]} {[-0.8905]} {[0]} {[-2.2923]} {[1.4684]} {[-0.9448]} {[-2.2418]} {[0.9512]} {[-0.8130]} {[-2.0995]} {[0.8104]} {[-0.8907]} {[0]} {[-2.2923]} {[1.4684]} {[-0.9448]} {[-2.2422]} {[0.9504]} {[-0.8144]} {[-2.1019]} {[0.8087]} {[-0.8898]} {[0]} {[-2.2912]} {[1.4685]} {[-0.9444]} {[-2.2416]} {[0.9508]} {[-0.8141]} {[-2.1000]} {[0.8095]} {[-0.8902]} {[0]} {[-2.2890]} {[1.4683]} {[-0.9440]} {[-2.2415]} {[0.9539]} {[-0.8127]} {[-2.0979]} {[0.8090]} {[-0.8904]} {[0]} {[-2.2890]} {[1.4683]} {[-0.9440]} {[-2.2418]} {[0.9548]} {[-0.8124]} {[-2.0980]} {[0.8084]} {[-0.8902]} {[0]} {[-2.2880]} {[1.4684]} {[-0.9440]} {[-2.2422]} {[0.9563]} {[-0.8108]} {[-2.0971]} {[0.8088]} {[-0.8907]} {[0]} {[-2.2872]} {[1.4683]} {[-0.9441]} {[-2.2430]} {[0.9583]} {[-0.8085]} {[-2.0961]} {[0.8084]} {[-0.8910]} {[0]} {[-2.2860]} {[1.4674]} {[-0.9443]} {[-2.2444]} {[0.9607]} {[-0.8037]} {[-2.0952]} {[0.8078]} {[-0.8919]} {[0]} {[-2.2860]} {[1.4674]} {[-0.9443]} {[-2.2449]} {[0.9618]} {[-0.8022]} {[-2.0950]} {[0.8075]} {[-0.8922]} {[0]} {[-2.2856]} {[1.4670]} {[-0.9445]} {[-2.2454]} {[0.9615]} {[-0.8014]} {[-2.0952]} {[0.8076]} {[-0.8922]} {[0]} {[-2.2852]} {[1.4668]} {[-0.9447]} {[-2.2464]} {[0.9619]} {[-0.7998]} {[-2.0953]} {[0.8073]} {[-0.8924]} {[0]} {[-2.2845]} {[1.4671]} {[-0.9453]} {[-2.2474]} {[0.9619]} {[-0.7978]} {[-2.0961]} {[0.8068]} {[-0.8929]} {[0]}
  2 件のコメント
lil brain
lil brain 2022 年 2 月 27 日
Cool! I thought you had to specify the column length
Voss
Voss 2022 年 2 月 27 日
In this case, all the cells contained scalars, so putting a scalar 0 in all cells in the 10th column of the cell array made sense.
If you needed to put matrices of different sizes in the 10th column of another cell array and have the new matrices match sizes with what's already there, then you would need to do something different. This answer just puts the scalar 0's in place.

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

その他の回答 (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