How to convert matrix to CSV file

2 次查看(过去 30 天)
Hello.
I want to convert matrix to CSV file.
When I used this code, I got this result.
I want to convert sequences{i} to each CSV file. Could you explain how to make eack CSV file using for loop?
clear all
close all
netCNN = googlenet;
dataFolder = "hmdb51_org";
[files,labels] = hmdb51Files(dataFolder);
idx = 1;
filename = files(idx);
video = readVideo(filename);
size(video)
labels(idx)
numFrames = size(video,4);
figure
for i = 1:numFrames
frame = video(:,:,:,i);
imshow(frame/255);
drawnow
end
inputSize = netCNN.Layers(1).InputSize(1:2);
layerName = "pool5-7x7_s1";
tempFile = fullfile(tempdir,"hmdb51_org.mat");
if exist(tempFile,'file')
load(tempFile,"sequences")
else
numFiles = numel(files);
sequences = cell(numFiles,1);
for i = 1:numFiles
fprintf("Reading file %d of %d...\n", i, numFiles)
video = readVideo(files(i));
video = centerCrop(video,inputSize);
sequences{i,1} = activations(netCNN,video,layerName,'OutputAs','columns');
end
save(tempFile,"sequences","-v7.3");
end
csvwrite('hmdb51_org/bend1.csv', sequences{1});
csvwrite('hmdb51_org/bend2.csv', sequences{2});
csvwrite('hmdb51_org/bend3.csv', sequences{3});

采纳的回答

Ajay Kumar
Ajay Kumar 2020-3-25
for i = 1:length(sequences)
csvwrite(['hmdb51_org/bend',num2str(i),'.csv'], sequences{i});
end
  2 个评论
Kong
Kong 2020-3-25
编辑:Kong 2020-3-25
Thank you so much.
There are 10 folders like bend, skip, walk, etc.
For example, sequences{i}
sequences{1 ~ 9} : /Bend
sequences{10 ~ 18} : /walk
............
Could you explain about this?
Ajay Kumar
Ajay Kumar 2020-3-25
编辑:Ajay Kumar 2020-3-25
You can write an if condition inside for loop. for eg:
for i = 1:length(sequences)
if i>0 && i<10
csvwrite(['hmdb51_org/bend',num2str(i),'.csv'], sequences{i});
elseif i>9 && i<19
csvwrite(['hmdb51_org/walk',num2str(i),'.csv'], sequences{i});
end
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by