Add name for each cell in MATLAB
조회 수: 5 (최근 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에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!