How to convert matrix to CSV file

6 ビュー (過去 30 日間)
Kong
Kong 2020 年 3 月 25 日
編集済み: Ajay Kumar 2020 年 3 月 25 日
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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by