How to convert matrix to CSV file

7 visualizaciones (últimos 30 días)
Kong
Kong el 25 de Mzo. de 2020
Editada: Ajay Kumar el 25 de Mzo. de 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});

Respuesta aceptada

Ajay Kumar
Ajay Kumar el 25 de Mzo. de 2020
for i = 1:length(sequences)
csvwrite(['hmdb51_org/bend',num2str(i),'.csv'], sequences{i});
end
  2 comentarios
Kong
Kong el 25 de Mzo. de 2020
Editada: Kong el 25 de Mzo. de 2020
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 el 25 de Mzo. de 2020
Editada: Ajay Kumar el 25 de Mzo. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by