If statement doesn't work while reading cell or vector

4 visualizaciones (últimos 30 días)
Ege Arsan
Ege Arsan el 12 de En. de 2021
Respondida: SaiDileep Kola el 15 de En. de 2021
I have the following if statement to determine a cell or a vector but i get en error or like this when i put in the file with vectors
opts = detectImportOptions(filename);
opts = setvartype(opts, 'char');
C = readcell(filename,opts);
if ~isnumeric(C)
numIdx = cellfun(@isnumeric,C);
C(numIdx) = cellfun(@num2str,C(numIdx),'UniformOutput',false);
Cnum = cellfun(@str2num,C,'UniformOutput',false);
elseif ~ischar(C)
charIdx = cellfun(@ischar,C);
C(charIdx) = cellfun(@srt2num,C(charIdx),'UniformOutput',false);
Cnum = cellfun(@str2num,C(charIdx),'UniformOutput',false);
end
Error using str2num (line 35)
Input must be a character vector or string scalar.
Error in Uni_Vib_Sol (line 33)
Cnum = cellfun(@str2num,C,'UniformOutput',false);
so the elseif statement doesn't seem to work

Respuestas (1)

SaiDileep Kola
SaiDileep Kola el 15 de En. de 2021
Can you send the sample file which you are checking the code with, so that issue can be reproduced

Categorías

Más información sobre Scope Variables and Generate Names en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by