How to avoid Warning when assigning values to a table

조회 수: 25 (최근 30일)
Louise Wilson
Louise Wilson 2021년 3월 25일
댓글: Louise Wilson 2021년 3월 25일
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);
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2021년 3월 25일
Not any more

댓글을 달려면 로그인하십시오.

추가 답변 (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