MATLAB Answers

How to avoid Warning when assigning values to a table

13 views (last 30 days)
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

Accepted Answer

Cris LaPierre
Cris LaPierre on 25 Mar 2021
Edited: Cris LaPierre on 25 Mar 2021
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);

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by