Info

This question is closed. Reopen it to edit or answer.

[HELP plz] How to seperate Column Data into values greater than and less than all into new Column

1 view (last 30 days)
Hi
I have a problem, where i get undefined function gt and so on...annoying and cant figure why..been searching the net and no luck. here is the question:
i have a matrix with: 137242x1 cell called V. containing some voltage. what i want this code to do is seperate the voltages so it makes a new Column with Values greater than 230 into 1 Cell for itself..and values less than 225 into another..and values remaining at 225-230.
i have for starters used for..but not working:
n = 1;
i = 0;
for i=1:length(V)
X = V > 230
end
help please :)
  5 Comments
awda
awda on 17 Mar 2014
Undefined function 'gt' for input arguments of type 'cell'.
Error in test1 (line 38) k_1 = U(U>230); %
Walter Roberson
Walter Roberson on 18 Mar 2014
If U is a cell array then U' does not turn it into a vector: it takes the transpose of the cell array leaving a cell array as the result.

Answers (1)

Walter Roberson
Walter Roberson on 17 Mar 2014
If each cell contains exactly one scalar, then the simplest to program is
U = cell2mat(V);
and then work with the numeric matrix U in ways similar to what Metin showed.
idx1 = U > 230;
idx2 = U < 225;
idx3 = ~(idx1 | idx2);
k_1 = U(idx1);
k_2 = U(idx2);
k_3 = U(idx3);
  2 Comments
awda
awda on 17 Mar 2014
this is what i get:
Error using cat Dimensions of matrices being concatenated are not consistent.
Error in cell2mat (line 84) m{n} = cat(1,c{:,n});
Error in test1 (line 36) U = cell2mat(V);
Walter Roberson
Walter Roberson on 18 Mar 2014
Your cell array is not completely numeric. The string in your first cell is causing the problem.
Do as I showed above but starting with
U = cell2mat(V(2:end));
Provided that all the other entries are numeric scalars.
Question: do the cells hold strings rather than numeric values??

Community Treasure Hunt

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

Start Hunting!