copy corresponding values of 2nd metrics depend on 1st metrics values

조회 수: 3 (최근 30일)
Amila
Amila 2022년 11월 30일
답변: VBBV 2022년 11월 30일
I have a two metrics in similer size lets say X and Y. I want to check the values in X and it it satisfind the requirement I want to copy coresponding Y element to separate metricxs Z, Z2, Z3
what i did is some thing like this
Z=[]
ii=0
Z2=[]
iii=0
Z3=[]
iiii=0
[RawX, ColX]= size(X)
j=1:RawX;
for n=1:ColX
if 100< X(j)<=300
ii=ii+1
Z(ii)=Y(j);
elseif if 300< X(j)<=400
iii=iii+1
Z2(iii)=Y(j);
else 400<X(j)<=500
iiii=iiii+1
Z3(iiii)=Y(j)
end
end
but im geting error
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
can you please help me

채택된 답변

VBBV
VBBV 2022년 11월 30일
Z=[];
ii=0
ii = 0
Z2=[];
iii=0;
Z3=[];
iiii=0;
X = rand(10)
X = 10×10
0.9550 0.0528 0.3988 0.4975 0.7866 0.9424 0.2501 0.1528 0.6154 0.5278 0.8411 0.4808 0.4519 0.0127 0.6746 0.9043 0.7531 0.2694 0.6852 0.1152 0.6055 0.2063 0.3776 0.3398 0.3013 0.1026 0.3232 0.1187 0.1144 0.3154 0.6749 0.4006 0.3833 0.5210 0.2074 0.6915 0.4091 0.9405 0.9099 0.2460 0.5347 0.6288 0.1128 0.8486 0.9665 0.7050 0.3994 0.2600 0.4173 0.0007 0.6950 0.4900 0.9118 0.0861 0.6187 0.0779 0.4888 0.9111 0.6740 0.8997 0.9076 0.0074 0.0239 0.4018 0.2651 0.9420 0.6340 0.2600 0.7264 0.4563 0.6546 0.9304 0.7353 0.6589 0.3517 0.2979 0.9512 0.8805 0.3336 0.9582 0.9904 0.7073 0.0651 0.7886 0.2412 0.1601 0.0626 0.3314 0.7760 0.3133 0.7171 0.5072 0.8630 0.0368 0.7734 0.3215 0.8643 0.3409 0.2823 0.7226
Y = rand(10)
Y = 10×10
0.1704 0.8017 0.0205 0.4158 0.7554 0.3214 0.8027 0.3020 0.9977 0.4332 0.2569 0.3404 0.2607 0.0886 0.7803 0.3954 0.0559 0.2862 0.6263 0.7057 0.8485 0.2298 0.1175 0.9574 0.8146 0.4981 0.4196 0.4720 0.8239 0.9954 0.8642 0.3274 0.0782 0.7858 0.9190 0.6252 0.6087 0.4671 0.3124 0.4045 0.8691 0.1809 0.5842 0.2886 0.2138 0.5709 0.7740 0.4126 0.0743 0.2323 0.1690 0.2461 0.1627 0.2844 0.3157 0.7184 0.6950 0.2450 0.9863 0.9395 0.7306 0.1196 0.3231 0.3055 0.7063 0.9774 0.9120 0.3559 0.0500 0.3417 0.1630 0.9525 0.5878 0.0733 0.9825 0.0536 0.9909 0.4954 0.6741 0.2727 0.2753 0.8191 0.0867 0.6823 0.1238 0.4268 0.0039 0.0932 0.6092 0.1667 0.9370 0.7577 0.1246 0.1005 0.9175 0.8412 0.6232 0.8542 0.5723 0.1105
[RawX, ColX]= size(X)
RawX = 10
ColX = 10
for j=1:RawX;
for n=1:ColX
if 100< X(j,n)<=300
ii=ii+1;
Z(ii)=Y(j,n);
elseif 300< X(j,n)<=400
iii=iii+1;
Z2(iii)=Y(j,n);
else 400<X(j,n)<=500
iiii=iiii+1;
Z3(iiii)=Y(j,n);
end
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Analysis of Variance and Covariance에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by