How to obtain values that meet a condition and store them in another variable without overwriting

조회 수: 1 (최근 30일)
Hi Matlab comunity,
So I have a variable called ALPHA, which has a 4x3 size and contains the following values
ALPHA = [29.1153, 36.8323, 38.2052; 40.9845, 40.9845, 40.9845; 19.1654, 19.1654, 19.1654; 3.0297, 8.7400, 33.9362];
This variable was obtained by extracting elements from one field from one structure that sometimes has 2x1 matrices, 1x1, 3x1 and no more than 3 values. I don't really mind if some values are repeted in this variable (I don't know why, I guess because since Matrices cannot be uneven, Matlab filled out to have a equally distributed matrix). The thing is that I want to create another variable that either extracts the values that lies equal or larger than 8 and smaller or equal than 12. If there is no value, then I want "0" as a value. The result for this example would be a row vector:
CF= [0 ; 0; 0 ; 8.7400] ;
A plus would be that insted of repeted values I could replace those repeted with "0" in their respective column. For example, ALPHA(2,2) = 0 and ALPHA (2,3) = 0. I haven't tried this but this is my code so far and I only get errors:
ALPHA= transpose(ALPHA); %get a row vector
CF= []; % prealocate vector
int= 1; %counter
for NV= 1:length(ALPHA);
CF(int,: )= find(ALPHA(int, :) >=alpha_min & ALPHA(NV ,:)<=alpha_max);
CF(int,: ) = ALPHA(CF(int,:));
if isempty(CF(NV));
CF(int,:)= 0;
end
int= int+1; %updating counter
end
As a result, I only get either 0's , a row vector of 4 elements (all 8.7400) or my favorite message "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side".
Could you take a look and let me know what is wrong? I hope I was clear with my explanation.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by