cell arrays not explicited
1 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have a 2 cells array, which come from an answer, with the format:
The cell {1,1} is:
Then typing A{1,1} i can see it explicited, as i expect. But if i want to see it inserted in a loop like:
A=answer
for j=1:length(answer)
A{j}=answer{1,j}
end
i can see again A like in the first image.
WHy and how can i avoid that?
thanks!!
0 个评论
回答(2 个)
Jan
2022-6-17
编辑:Jan
2022-6-17
A = answer; % Why? You do this again here:
for j = 1:numel(answer) % NUMEL is safer than LENGTH
A{j} = answer{1,j};
celldisp(A{j})
% Or:
% fprintf('%s\n', A{j}{:})
end
Matlab tries to be smart an chooses a compact output as default. To get an explicit output, use explicit output commands.
4 个评论
Jan
2022-6-19
@Pas182: The first screenshot does not look like an Excel table. While "{1 x 8 cell}" is meaningful in Matlab, it is just strange in Excel.
The 2nd output does not look like Excel also. So I still do not know, what you want to achieve. "HELP ME PLEEEASE" - focus on explaining, which output is wanted.
Voss
2022-6-19
Here's a table T that matches the screen shot:
Dtc = {'P0C43';'P0532';'P1C68'};
Lamp = {'3 trip MIL';'3 trip MIL';'1 trip Wrench'};
Verification = { ...
{ 'DTC_enabled' '1_trip_failed' '2_trip_NOT_failed' '3 trip NOT failed' '1 trip NOT healed' '2 trip NOT healed' '3 trip NOT healed' 'MIL NOT healed'}; ...
{ 'DTC_enabled' '1_trip_failed' '2_trip_NOT_failed' '3 trip NOT failed' '1 trip NOT healed' '2 trip NOT healed' '3 trip NOT healed' 'MIL NOT healed'}; ...
{ 'DTC_enabled' '1_trip_failed' '1 trip NOT healed' '2 trip healed' 'WRENCH healed'} ...
};
T = table(Dtc,Lamp,Verification)
Verification is a single variable/column (in the table T), each element of which is a cell array of character vectors.
T.Verification{:}
Do you want Verification to take up 8 columns of T instead of 1?
4 个评论
Image Analyst
2022-6-19
编辑:Image Analyst
2022-6-19
I think you can still just create a table dynamically like for one row
for row = 1 : height(t)
thisCell = t.Verification{row}; % Extract one cell array
t.Column1{row} = thisCell{1};
t.Column2{row} = thisCell{2};
t.Column3{row} = thisCell{3};
t.Column4{row} = thisCell{4};
t.Column5{row} = thisCell{5};
t.Column6{row} = thisCell{6};
t.Column7{row} = thisCell{7};
t.Column8{row} = thisCell{8};
end
If you need any more help, let's use your actual table so attach it in a .mat file with the paperclip icon
save('answers.mat', 't'); % Save your table "t" in file "answers.mat"
If height(t) doesn't work, use size(t, 1) instead.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!