Hi everybody. I have two problems. I think they are simple to solve but I cannot at this time!!!, I don't know how!!!
First problem: I constructed a matrix dkc of size (1057 X 11), and many zeros inside. I used this code to remove zeros:
for g=1:11
new_variable = dkc( dkc(:,g)~=0, 2);
end
but I got the resulted matrix in only one column. I want the matrix as it is, 2D with 11 columns, without zeros in the array.
Second problem I have, when I have another column say s with a different length than the previous matrix dkc. Can I check which column in dkc is nearest in its elements with this elements of s? and how? And which method will use?
Thanks for all, and really I need urgently these solutions to complete my research.

 채택된 답변

dpb
dpb 2014년 3월 20일
편집: dpb 2014년 3월 20일

0 개 추천

for g=1:11
new_variable = dkc(dkc(:,g)~=0, 2);
end
A) The above replaces new_variable each pass through so what you're left with is the last column for the logical addressing array for the row selection and the second column from the fixed 2.
B) Matlab cannot store "jagged" arrays--to actually not have anything as a placeholder for the zeros the only way you can do this is with a cell array. Or, if you just need an indicator consider substituting NaN -- certain Matlab functions are enabled that they will skip those elements altho certainly that's not universal.
To build the jagged array via your loop solution,
nv=cell(1,11); % an empty cell array of 11 columns
for i=1:11
nv(i)={dkc(dkc(:,i)~=0,i)};
end
NB the curlies "{}" to turn the double vector into a cell array

댓글 수: 8

Hany Elsalamony
Hany Elsalamony 2014년 3월 20일
Thank you very much, it is working; but how can i assign the nearest cell from these with the another cell S (of another external unequal array) say 705 x 1, to get which one of them will be nearest. Also what is suitable method to get the best matching?
Thanks again for your great cooperation
Hany Elsalamony
Hany Elsalamony 2014년 3월 20일
Or, matching with another matrix of other cells to get which are nearest to these cells in dkc (one cell by one) or value by value.
dpb
dpb 2014년 3월 20일
Hard to say what would be "best" matching if they're of noncommensurate length -- what would you define as "matching"? Nearest average, minimum maximum difference, ...?
Hany Elsalamony
Hany Elsalamony 2014년 3월 21일
Many thanks for your response, actually, i got an idea, that is extending the shorter array of data or shrinking the longer one to be equal then i can match, but i don't know how i can do this. What is your opinion about this idea? suggest one.
dpb
dpb 2014년 3월 21일
Well, either concatenate to the shorter or select from the longer the subset. The latter would be sotoo
minRows = min(size(x,1), size(y,1)); % minimum rows in the two
x = x(1:minRows, :);
y = y(1:minRows, :);
Hany Elsalamony
Hany Elsalamony 2014년 3월 21일
By this way, will we neglect some elements from the longer to be shorter?And these values eliminated (or cutting) from the end of longer array will not affect on the array??
dpb
dpb 2014년 3월 22일
Yes, the above selects the first N rows where N is the min(size(...,1)) for the two. Yes, it therefore ignores the remainder after that in the longer and they're gone forever into the bit bucket in the sky...
Whether that's an acceptable result on the array or not depends entirely on what your application needs -- we can't answer that, only you can.
Hany Elsalamony
Hany Elsalamony 2014년 3월 23일
Thank you so much for your help, great cooperation, your time, and efforts.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2014년 3월 19일

댓글:

2014년 3월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by