Re: cell array to normal array
- From: "Titus" <titus.edelhofer@xxxxxxxxxxxx>
- Date: Wed, 31 Oct 2007 14:41:14 +0100
"Eszter " <gulacsy@xxxxxxxxxxx> schrieb im Newsbeitrag
news:fg9s3s$fi7$1@xxxxxxxxxxxxxxxxxxxxx
I am wondering if anyone could help me with this as I
tried searching to the solution to this problem on Matlab
Central, but no success. Tried cell2num, but it didn't
work.
I have a cell array with each cell containing a string of
four numbers of varying length, e.g. '434.23 4567.7
312 34567.98' I have about 400 rows of this type of
data - four numbers with varying significant digits.
I concluded from the help file that I could create a
variable from each cell of the cell array, but doing that
four 400 rows is tedious, so I am wondering if there is an
easier way to convert this cell array to a matrix,
containing 400 rows with a string of numbers in each row.
Cell2mat doesn't seem to work as the strings in the cells
of the cell array are not all the same length.
Thanks in advance for any help.
Eszter
Hi Eszter,
sometimes a loop is the easiest way to do things like that:
say x is a cell array of length 400, then:
m = zeros(400, 4);
for i=1:400
m(i,:) = str2num(x{i});
end
gives you a 400x4 matrix. But if you prefer not to use loops:
mm = cellfun(@(v) str2num(v)', x, 'UniformOutput', false);
m = [mm{:}]';
gives the same result...
Titus
.
- Follow-Ups:
- Re: cell array to normal array
- From: Eszter
- Re: cell array to normal array
- References:
- cell array to normal array
- From: Eszter
- cell array to normal array
- Prev by Date: m editor ->nedit?
- Next by Date: Re: ksdensity (not unique?)
- Previous by thread: cell array to normal array
- Next by thread: Re: cell array to normal array
- Index(es):
Relevant Pages
|