Add name for each cell in MATLAB
6 次查看(过去 30 天)
显示 更早的评论
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 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!