フィルターのクリア

how to replace by comparing in a double array.?

2 ビュー (過去 30 日間)
aditya kumar sahu
aditya kumar sahu 2016 年 11 月 16 日
コメント済み: Jan 2016 年 11 月 21 日
I have 4 double matrix, one is c(i,j) of size 256*8,having only 0 and 1 as its elements and z=[0 1 1 1 1 1 1 1 ] and y=[1 0 0 0 0 0 0 0] and b=[ 0 1 0 1 0 1 0]
i want to compare each row of c with z,y,b with below condition.
if any row of c(i,j) matches with z or y and if b(k)==0 then that row of c(i,j)=z,
otherwise/else
c(i,j) matches with z or y but b(k)==1 then that row of c(i,j)=y, else c(i,j) values remain same
i have written the code as this
[row]=size(c);
[row1]=size(b)
for i=1:row
if c(i,:)== z | c(i,:)==y
for k=1:row1
if b(k)==0
p(i,:)= z;
else
p(i,:)= y;
end
end
end
end
i could not find where is the wrong why the matrix p does not have the values required..
Thank you in advance.
  3 件のコメント
KSSV
KSSV 2016 年 11 月 16 日
aditya kumar sahu
aditya kumar sahu 2016 年 11 月 17 日
if any row of c(i,j) matches with z or y and if b(k)==0 then that row will be c(i,j)=z,
otherwise/else
c(i,j) matches with z or y but b(k)==1 then that row will be c(i,j)=y, else c(i,j) values remain same

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2016 年 11 月 16 日
編集済み: Jan 2016 年 11 月 16 日
A bold guess:
[row]=size(c)
for i=1:row
...
Note that row is a vector and the expression 1:row does most likely not do, what you expect. Try:
row = size(c, 2); % Or: numel(c)
for i = 1:row
Do you know and use the debugger? You can set breakpoint in lines and step through the code line by line. This helps to find such problems and it is much more efficient than asking the forum.
  2 件のコメント
aditya kumar sahu
aditya kumar sahu 2016 年 11 月 17 日
if any row of c(i,j) matches with z or y and if b(k)==0 then that row will be c(i,j)=z,
otherwise/else
c(i,j) matches with z or y but b(k)==1 then that row will be c(i,j)=y, else c(i,j) values remain same
Jan
Jan 2016 年 11 月 21 日
@aditya: Repeating sentences from the original question does not add any new information.
Did you notice my suggestion:
When you claim, that the posted code is "wrong", please add the information, why you think so.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by