How to put a matrix into an cell element?

15 ビュー (過去 30 日間)
Akash Menon
Akash Menon 2019 年 3 月 4 日
編集済み: Akash Menon 2019 年 3 月 5 日
five.PNG
Hi everyone,
I have a cell array called inputs2 with 7 coloumns and 10001 rows. I want to be able to take each row entry and combine it to a single matrix and put that into a cell array like shown below.
four.PNG
% So like this
[0.8668;0.3571;0.2254;0.7989;0.4415;0.1627;0.3671] in the first cell and so on [..;..;..;..;..;..;..;]... for the 10001 entries.

採用された回答

Akash Menon
Akash Menon 2019 年 3 月 5 日
編集済み: Akash Menon 2019 年 3 月 5 日
for i=1:10001
new_cell{i}=vertcat(input_test1{i,1},input_test1{i,2},input_test1{i,3},input_test1{i,4},input_test1{i,5},inputs_test1{i,6},input_test1{i,7});
end
new_cell=new_cell'; % Transpose if you want
% Alternatively if you desire the individual cells to have a row matrix- use 'horzcat' instead of 'vertcat'
% If you have more coloumns- use a nested loop (for j=1:(number of coloumns)) after the first loop
% Example for i=1:10000
% for j=1:7
% new_cell{i}=vertcat(input_test{i,j});
% end
% end
You should get a result as shown on the left.
Hope it helps!

その他の回答 (1 件)

Kevin Phung
Kevin Phung 2019 年 3 月 4 日
new_M = cell(1,size(inputs2,1));
for i = 1:size(inputs2,1)
new_M{i} = inputs2{1}(i,:)
end
  1 件のコメント
Akash Menon
Akash Menon 2019 年 3 月 5 日
編集済み: Akash Menon 2019 年 3 月 5 日
Hey!
Thanks for the response.
Unfortunately this didn't work. I just had a long day and couldn't think .Figured it out now. Posted back above.

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

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by