Add name for each cell in MATLAB
6 ビュー (過去 30 日間)
古いコメントを表示
omid
2023 年 5 月 10 日
回答済み: Antoni Garcia-Herreros
2023 年 5 月 10 日
Hello friends, I created a csv file, and I want to define the first row with the name (id) and the next three cells (1 and zeros) with three names ('Absent', 'Present', 'Unknown').
How can I do it?
clc
clear
close all
cd training_data_out\
folderInfo = dir('**/*_MV.wav');
cd ..\
addpath training_data_out\
load('trainingdataa');
label=[];
totalimage=[];
for i=1:length(folderInfo)
filename = folderInfo(i).name;
[x,Fs] = audioread(filename);
x=decimate(x,4);
% label extraction
% finding different labels in text file ('Absent','Present','Unknown')
trainingdataa(:,1)=strcat(trainingdataa(:,1),'_MV.wav');
[row,column]=find(contains(trainingdataa(:,1),filename));
if trainingdataa(row,8)=='Present';
label=[label;{filename(1:end-7),1,0,0}];
elseif trainingdataa(row,8)=='Absent';
label=[label;{filename(1:end-7),0,1,0}];
else
label=[label;{filename(1:end-7),0,0,1}];
end
writecell(label,'newlabel.csv')
0 件のコメント
採用された回答
Antoni Garcia-Herreros
2023 年 5 月 10 日
Hello Omid,
I'm assuming that what you want to label are the columns and not the rows.
We cannot run your code because we don't have acces to your "trainingdata".
But let's say you are able to produce a matrix (M) with size n x 4 like the one in the csv file you attached.
Then:
T=array2table(M); % Create a table from the matrix
T.Properties.VariableNames={'id','Absent','Present','Unknown'}; % Add the column headers
writetable(T,'NewFile.xls','WriteVariableNames',true);
Hope this helps!
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!