How to avoid Warning when assigning values to a table

24 次查看(过去 30 天)
Hello,
I have the attached table. I create an empty table and then add each variable separately from the name of files in a folder, and then assign them one by one for each row. This works, but I get a warning:
'Warning: The assignment added rows to the table, but did not assign values to all of the table's existing variables. Those variables are extended with rows containing default values. '
So even though there are no problems, I would like to do it in the most robust way. How can I avoid the warning? Is there a way to assign all variables at once for each row?
wavTimes.(rec_SN)=[]; %create empty output table
wavTimes.(rec_SN)=array2table(wavTimes.(rec_SN));
%get start and end time of each .wav file in folder
for ii=1:length(d)
disp(d(ii).name);
filename=fullfile(rec, d(ii).name);
split_fn=strsplit(filename,'.');
wav_date=datetime(split_fn{2},'InputFormat','yyMMddHHmmss');
wavTimes.(rec_SN).wavFileName(ii)={d(ii).name};
wavTimes.(rec_SN).wavDateTime(ii)=wav_date;
wavinfo=audioinfo(filename);
wav_length=wavinfo.Duration;
wavTimes.(rec_SN).wavEnd(ii)=wav_date+seconds(wav_length);
end

采纳的回答

Cris LaPierre
Cris LaPierre 2021-3-25
编辑:Cris LaPierre 2021-3-25
The warning is because you are adding the values to a table one by one. When you add the first value in a new row, all columns are assigned a value. The warning is just that, a warning to let you know values were added to the other variables.
Consider rearranging your setup slightly.
%get start and end time of each .wav file in folder
for ii=1:length(d)
disp(d(ii).name);
filename=fullfile(rec, d(ii).name);
split_fn=strsplit(filename,'.');
wav_date=datetime(split_fn{2},'InputFormat','yyMMddHHmmss');
wavFileName(ii)={d(ii).name};
wavDateTime(ii)=wav_date;
wavinfo=audioinfo(filename);
wav_length=wavinfo.Duration;
wavEnd(ii)=wav_date+seconds(wav_length);
end
wavTimes.(rec_SN) = table(wavFileName,wavDateTime,wavEnd);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by