I am getting error "Cell contents reference from a non-cell array object" . Please tell me how to solve this problem.
Cell contents reference from a non-cell array object.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
marcos flavio paula miranda junior
il 22 Nov 2020
Commentato: marcos flavio paula miranda junior
il 22 Nov 2020
clc;
clear all;
vchave = [2 2 2 2 2 2]
for k = 1:6;
v{k} = vchave
v{1,k} = v{1,k}-1
v{1}{k+1} = v{1}{k+1}-1
end
I am getting error "Cell contents reference from a non-cell array object" . Please tell me how to solve this problem.
Risposta accettata
Stephen23
il 22 Nov 2020
Modificato: Stephen23
il 22 Nov 2020
Each cell of v contains a numeric vector. So your indexing here:
v{1}{k+1} = v{1}{k+1}-1
% ^ ^ ^ ^ wrong type of bracekts for numeric array.
uses the wrtong type of brackets for indexing (curly braces are used to access the elements of a container array, e.g. the elements of a cell array, table, or string). The correct brackets for accessing the elements of a numeric array are parentheses, as shown here:
vchave = [2,2,2,2,2,2];
for k = 1:5;
v{k} = vchave
v{1,k} = v{1,k}-1
v{1}(k+1) = v{1}(k+1)-1
end
I strongly recommend preallocating v before the loop.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Labels and Styling in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!