Code covered by the BSD License  

Highlights from
cell2vars: Transform cell to vars

1.5

1.5 | 2 ratings Rate this file 21 Downloads (last 30 days) File Size: 2 KB File ID: #37290
image thumbnail

cell2vars: Transform cell to vars

by

 

25 Jun 2012 (Updated )

cell2vars: Transform cell's columns' to variables in workplace

| Watch this File

File Information
Description

% PURPOSE: Convert the cell's columns' to variables in matlab workspace
% -----------------------------------------------------------------------------
% SYNTAX:
% (1) cell2vars(cellvar)
% (2) cell2vars(cellvar, newvarname)
% -----------------------------------------------------------------------------
% OUTPUT:
% (1) each column of the cell is been transform to a variable in matlab
% workspace
% -----------------------------------------------------------------------
% INPUT:
% (1) cellvar: NxM --->a cell containing M columns. Each column include
% a head and its body.
% (2) newvarname: 1xM ---> M string as new head for the column.
% NB: no string can be include in the file.

% -----------------------------------------------------------------------
% LIBRARY:
% -----------------------------------------------------------------------
% SEE ALSO: vars2cell,
% -----------------------------------------------------------------------
% REFERENCE: assigni, eval
% -----------------------------------------------------------------------
% written by:
% Lin Renwen
% <linrenwen@gmail.com>

% Version 1.0 [2012-6-27 20:29:25]

%=============================================
% EXAMPLE:
% INPUT:
% > A = {'name','grade'; 1,56; 2,78; NaN,90};
% > cell2vars(A);
% > name
% name =
% 1
% 2
% NaN
%
% > grade
% grade =
% 56
% 78
% 90
% % END OF EXAMPLE
%=============================================

MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
12 Jun 2014 I. GARCIA  
26 Jun 2012 Renwen Lin

Thanks so much! I am thinking about your words, and would make adjustment! Thanks again!

26 Jun 2012 Jan Simon

It would be helpful if the description contains an example in valid Matlab syntax. Currently I do not understand the input format. It is not clear, why there is a 78 in the inputs, but a 58 in the outputs - a typo? And why does the NaN disappear?
Using ASSIGNIN to inject variables in the caller's workspace can impede the debugging massively: Imagine a variable is called "max". Then in non-debug mode the function max() is used, while in debug mode or in other commands of the EVAL-family the variable "max" is used. Cruel!
In addition the dynamically created variables decrease the processing speed. It would be much better to create a struct: no confusion, no efficiency leaks, no debugging horror.
LENGTH is smarter than MAX(SIZE(X)).
The commented block without any explanation might be meaningful for you, but for FEX users this is confusing only. Keeping code for later times as comments is a "programming anti-pattern": Whenever the code is changed, the programmer has to check if the commented section is concerned, such that deleting it would be better. Comments should support debugging, and not increase the complexity.
"iscellstr(data(:,ii))" wastes the time with creating "data(:,ii)". Better use "iscellstr(data)" once outside the loop.
I think this submission is neither useful nor usable. I cannot check reliably, if it works as advertised, because the weak help text does not define the procedure exactly.

Updates
27 Jun 2012

Adjust according to Jan Simon's suggestion. Jan thanks so much!

08 Oct 2012

Revise the example; thanks so much! Simon

Contact us