How to convert matrix to CSV file
조회 수: 3 (최근 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});
댓글 수: 0
채택된 답변
Ajay Kumar
2020년 3월 25일
for i = 1:length(sequences)
csvwrite(['hmdb51_org/bend',num2str(i),'.csv'], sequences{i});
end
댓글 수: 2
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 Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!