cell arrays not explicited

1 visualización (últimos 30 días)
Pas182
Pas182 el 17 de Jun. de 2022
Editada: Image Analyst el 19 de Jun. de 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!!

Respuestas (2)

Jan
Jan el 17 de Jun. de 2022
Editada: Jan el 17 de Jun. de 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 comentarios
Pas182
Pas182 el 17 de Jun. de 2022
@Jan my goal is to create an excel table like:
but until i can't get the third column in the right format i can't do it :(
Then I'm trying to find a way to explicit the array A in a way that the tab becomes something like:
HELP ME PLEEEASE!! thank you so much
Jan
Jan el 19 de Jun. de 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.

Iniciar sesión para comentar.


Voss
Voss el 19 de Jun. de 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 comentarios
Pas182
Pas182 el 19 de Jun. de 2022
@Image Analysti can't unfortunately because that function is in Matlab 2018 on, I'm using Matlab 2016b version :(
Image Analyst
Image Analyst el 19 de Jun. de 2022
Editada: Image Analyst el 19 de Jun. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by