How to avoid Warning when assigning values to a table

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 日

0 投票

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);

3 件のコメント

Louise Wilson
Louise Wilson 2021 年 3 月 25 日
Thanks Cris, that makes sense. Is there a typo in the final command?
Cris LaPierre
Cris LaPierre 2021 年 3 月 25 日
Not any more
Louise Wilson
Louise Wilson 2021 年 3 月 25 日
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

製品

リリース

R2020a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by