attempt to assign matlab matrix to an matrix of named variables produces 'too many output arguments' error -
the matlab function sscanf returns variable size matrix (or perhaps cell array?) can assigned matrix of variable names
>> clear ; line = '1 2' ; [a, sz] = sscanf( line, '%d %d' ) ;
it appears output matrix a
column matrix, can transposed form 1x2 matrix:
b = a' ;
i'd able assign matrix of variable names, can in preceding sscanf call. figured i'd able do:
[c,d] = b ;
but gives me error:
too many output arguments.
from reply http://stackoverflow.com/a/23800927/189270 looked may able transforming matrix a
cell array, however, don't seem able figure out right syntax this:
>> num2cell(a) ans = [1] [2] >> [c,d] = num2cell(a) error using num2cell many output arguments. >> [c,d] = num2cell(a') error using num2cell many output arguments. >> [c ; d] = num2cell(a) [c ; d] = num2cell(a) |
i can solve problem brute forcefulness assigning fields b
, c
1 @ time indexing matrix a
. however, imagine mutual type of mass variable assignment (i in mathematica example), wanted understand wrong attempts above, , right matlab syntax is.
you have correct. 1 time take numbers , convert them individual cells in cell array (through num2cell
), utilize deal
distribute each element in cell array corresponding variables. such:
%// code line = '1 2' ; [a, sz] = sscanf( line, '%d %d' ) ; %// new code! b = num2cell(a); [c,d] = deal(b{:});
this after deal
:
c = 1 d = 2
matlab
No comments:
Post a Comment