cell arrays not explicited
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Jan
on 17 Jun 2022
Edited: Jan
on 17 Jun 2022
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 Comments
Jan
on 19 Jun 2022
@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
on 19 Jun 2022
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 Comments
Image Analyst
on 19 Jun 2022
Edited: Image Analyst
on 19 Jun 2022
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.
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!