Assigning specific elements of vector a different value
이전 댓글 표시
Hi
I am trying to assign values to elements from one vector based on the values of another vector:
r = [1,3,4,5,3,3,4,5,6,4];
Postdia = [12,20]
For vector r, I want to pull out the element when the sum of r reaches 12 (Postdia First value) - and name it SYNAPSE. Similarly I want to pull out the element in r when the sum of the values reaches 20 (Postdia second value) - call it SYNAPSE also. The other values should all be assigned NO SYNAPSE.
For this I have written this code but it isn't working.
b= 0;
b2 = 0;
r = [1,3,4,5,3,3,4,5,6,4];
Postdia = [12,20]
r2 = r;
k = 0
for i = 1:length(r)
b = r(i) + b;
for j = 1:2
b2 = find(b > Postdia(j));
r2(i) = r(b2);
if b2 == 1
r2(i) = {'SYNAPSE'};
else
r2(i) = {'NO SYNAPSE'};
end
end
end
Does anyone have any suggestions?
Cheers
댓글 수: 2
James Tursa
2018년 1월 10일
What do you want for a result? A cell array the same size as r, but with either 'SYNAPSE' or 'NO SYNAPSE' for the elements depending on your criteria?
Morgan Roberts
2018년 1월 10일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Heath-Jarrow-Morton Tree Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!