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

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 commentaires

for any given U
if true
k_1 = U(U>230); %
k_2 = U(U<225);
k_3=U(~ismember(U,[k_1,k_2]))
end
Provided U is a numeric matrix. The V in the question is a cell array.
that is right it would be better to turn the cell array in vector form with
% U=U';
Undefined function 'gt' for input arguments of type 'cell'.
Error in test1 (line 38) k_1 = U(U>230); %
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.

Réponses (1)

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 commentaires

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);
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??

Cette question est clôturée.

Question posée :

le 17 Mar 2014

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by