Create a matrix using Unix command in Matlab!

3 views (last 30 days)
Hi jan, I am using Unix command in matlab to get bunch of columns which I will be manupulating subsequently. I was manage to use awk command to have output of R like 1x21 char and which looks like (14151617181920) instead I want it in a cell. I tried using cellstr in it but didn't get much success. Ultimately I want to collpase all the columns 14,15,16,17,18,19,20 by taking mean across the columns. Can you please help me in this?
  1 Comment
Jan
Jan on 7 May 2012
Do you mean me? If so, I do not understand the question. What "bunch of columns" do you get? To which type of variable do you want to convert the string '14151617181920'? Would SSCANF be helpful? What does "not much success" explicitly mean? Please post your code and the error message, if you get one.

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 7 May 2012
Please command
double(R)
and look for entries that are not in the range 48 to 57. 48 corresponds to '0', 49 to '1', up to 57 corresponding to '9'. Look for 32 (space), 13 (carriage return), 10 (line feed). If those other characters are present, they are important to separating the parts.
If those characters are not present, then you probably have a problem in the awk code. awk is not really an appropriate topic here, but if the awk code is relatively short, perhaps someone will happen to understand it. (perl has a stronger tie to MATLAB than awk does.)

Jan
Jan on 7 May 2012
I guess that you want to convert the string '14151617181920' to the vector [14, 15, 16, 17, 18, 19, 20].
R = '14151617181920';
V = sscanf(R, '%2d');
meanV = mean(V);

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!