How to convert matrix to CSV file

11 views (last 30 days)
Kong
Kong on 25 Mar 2020
Edited: Ajay Kumar on 25 Mar 2020
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});

Accepted Answer

Ajay Kumar
Ajay Kumar on 25 Mar 2020
for i = 1:length(sequences)
csvwrite(['hmdb51_org/bend',num2str(i),'.csv'], sequences{i});
end
  2 Comments
Ajay Kumar
Ajay Kumar on 25 Mar 2020
Edited: Ajay Kumar on 25 Mar 2020
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

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Analysis 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!