필터 지우기
필터 지우기

Problem with array and save file?

조회 수: 1 (최근 30일)
Anh
Anh 2023년 4월 4일
댓글: Anh 2023년 4월 5일
%% create
a = cell(10,5,3);
for participant = 1:10
for video = 1:5
a{participant,video,1} = participant ;
a{participant,video,2} = video ;
a{participant,video,3} = [
"Searching for Bobby Fischer",...
"D.O.A.",...
"The Hangover",...
"The Ring",...
"300",...
];
end
end
b = cell2table(num2cell(reshape( a, [10*5, 3])),...
'VariableNames', {'participant'; 'video'; 'video_name'});
writetable(b, 'load.xlsx', 'Sheet', 1);
I have some problem with my code above. I want to write a table like each video contain with each video_name like this
but my code for a table like this
How can i do to solve this problem? Can someone edit with my code? thank you

채택된 답변

MarKf
MarKf 2023년 4월 4일
Do you need a 3D cell and then rehsape it or can you create it like the 2D table you want already?
videosn = ["Searching for Bobby Fischer",...
"D.O.A.",...
"The Hangover",...
"The Ring",...
"300"];
Nparticipants = 10; Nvideos = numel(videosn);
a = cell(Nparticipants*Nvideos,3);
for video = 1:Nvideos
for participant = 1:Nparticipants
idx = Nparticipants*(video-1)+participant;
a{idx,1} = participant;
a{idx,2} = video;
a{idx,3} = videosn(video);
end
end
b = cell2table(a,'VariableNames', {'participant'; 'video'; 'video_name'})
b = 50×3 table
participant video video_name ___________ _____ _____________________________ 1 1 "Searching for Bobby Fischer" 2 1 "Searching for Bobby Fischer" 3 1 "Searching for Bobby Fischer" 4 1 "Searching for Bobby Fischer" 5 1 "Searching for Bobby Fischer" 6 1 "Searching for Bobby Fischer" 7 1 "Searching for Bobby Fischer" 8 1 "Searching for Bobby Fischer" 9 1 "Searching for Bobby Fischer" 10 1 "Searching for Bobby Fischer" 1 2 "D.O.A." 2 2 "D.O.A." 3 2 "D.O.A." 4 2 "D.O.A." 5 2 "D.O.A." 6 2 "D.O.A."
% writetable(b, 'load.xlsx', 'Sheet', 1);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by