How to figure out if an array is ordinary or cell?

1 Ansicht (letzte 30 Tage)
Sam136
Sam136 am 7 Jul. 2015
Bearbeitet: bio lim am 8 Jul. 2015
In my code, variable (A) can be either an ordinary array or cell array. How can I do following
If (A) is an ordinary array then do nothing If (A) is a cell array then cell2mat(A)

Akzeptierte Antwort

bio lim
bio lim am 7 Jul. 2015
Bearbeitet: bio lim am 8 Jul. 2015
tf = iscell(A);
if tf == 1
A =cell2mat(A)
end
  2 Kommentare
Steven Lord
Steven Lord am 7 Jul. 2015
Two comments:
  1. You don't need to use == 1 here.
  2. You need to return an output argument from CELL2MAT, otherwise you're making a matrix from the cell array then throwing that matrix away.
bio lim
bio lim am 8 Jul. 2015
Thank you. I'll correct it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by