Azzera filtri
Azzera filtri

Add name for each cell in MATLAB

5 visualizzazioni (ultimi 30 giorni)
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')

Risposta accettata

Antoni Garcia-Herreros
Antoni Garcia-Herreros il 10 Mag 2023
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!

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by