cell arrays not explicited

2 views (last 30 days)
Pas182
Pas182 on 17 Jun 2022
Edited: Image Analyst on 19 Jun 2022
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!!

Answers (2)

Jan
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
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.

Sign in to comment.


Voss
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)
T = 3×3 table
Dtc Lamp Verification _________ _________________ ____________ {'P0C43'} {'3 trip MIL' } {1×8 cell} {'P0532'} {'3 trip MIL' } {1×8 cell} {'P1C68'} {'1 trip Wrench'} {1×5 cell}
Verification is a single variable/column (in the table T), each element of which is a cell array of character vectors.
T.Verification{:}
ans = 1×8 cell array
{'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'}
ans = 1×8 cell array
{'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'}
ans = 1×5 cell array
{'DTC_enabled'} {'1_trip_failed'} {'1 trip NOT healed'} {'2 trip healed'} {'WRENCH healed'}
Do you want Verification to take up 8 columns of T instead of 1?
  4 Comments
Image Analyst
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!