필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to save data

조회 수: 1 (최근 30일)
Fateme Jalali
Fateme Jalali 2015년 12월 10일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi; I have two data sets
A=[0 6 7 0 3 9 6 8 2 0 3 5];
B=[104 76 54 98 100 23 10 670 123 56 93 90];
when I see 0 in A, I should put its concurrent value from B to a cell till previous 0. for example when I see second 0 in A I should put 765498 in a cell. I need a code to do it. thanks
  댓글 수: 1
per isakson
per isakson 2015년 12월 11일
I don't get it!

답변 (1개)

Image Analyst
Image Analyst 2015년 12월 11일
What does "to a cell till previous 0" mean? Also, the first 0 in A is at index 1 and the value of B at index 1 is 104, not 765498 so I don't know how your example works.
Just taking a SWAG, maybe this is what you want:
A=[0 6 7 0 3 9 6 8 2 0 3 5];
B=[104 76 54 98 100 23 10 670 123 56 93 90];
indexesToReplace = (A==0);
A(indexesToReplace) = B(indexesToReplace)
It's replacing 0's in A with the value of B at the same index. Is that what you want???
  댓글 수: 2
Fateme Jalali
Fateme Jalali 2015년 12월 11일
i mean where 0 happened in A, i should align data in B from this 0 index to previous zero index.I actually want to correct this code:
w0=find(A,'0');
cel=cell(size(w0,2),1);
for i2=1:size(w0,2);
cel{i2}=B(w0(i2):w0(i2+1));
end
Fateme Jalali
Fateme Jalali 2015년 12월 11일
for example for second zero in A '76 54 98' should be saved in cel. for third 0 in A i should store ' 100 23 10 670 123 56' in cel.thanks

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by