Unable to perform assignment because the left and right sides have a different number of elements.

3 views (last 30 days)
Anouk Baeten
Anouk Baeten on 16 Jul 2021
Answered: Peter Perkins on 27 Jul 2021
%% save start date time
filename = 'Format_competition.xlsx';
table_starttimes = zeros(100,1);
formatOut = 'HH:MM:SS';
for ind = 1:length(table_starttimes);
date = datestr(now,formatOut)
table_starttimes(ind) = [date];
pause;
Error in tijd (line 7)
table_starttimes(ind) = [date];
I don't see why there are not an equal number of elements, can somebody help me?

Answers (3)

KSSV
KSSV on 16 Jul 2021
Edited: KSSV on 16 Jul 2021
%% save start date time
filename = 'Format_competition.xlsx';
table_starttimes = cell(100,1);
formatOut = 'HH:MM:SS';
for ind = 1:length(table_starttimes);
date = datestr(now,formatOut)
table_starttimes{ind} = date;
pause;

VBBV
VBBV on 16 Jul 2021
It's due to the HH:MM:SS format. Matlab treats 01:01:10 as an array instead of date. So, size of table_starttimes and [date] do not have same number of elements or size.

Peter Perkins
Peter Perkins on 27 Jul 2021
No idea what
filename = 'Format_competition.xlsx';
has to do with this, so I suspect you have not told us the whole story. In any case, don't use now, don't use datestr, use datetime:
table_starttimes = NaT(100,1);
for ind = 1:length(table_starttimes);
table_starttimes(ind) = datetime("now","Format","HH:mm:ss");
pause;
end

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by