If A2 and B7´s content were 1 - then how to fill A3 to A6 with ones by function??

1 次查看(过去 30 天)
Hi. I´ve described my problem in the picture... My action looked like that:
for m=2:e-a
if X(m,1)==1 || X(1:e-a,3)==1 && X(m,2)==0
X(m,3)=1;
else
X(m,3)=0;
end
end
That should be repeated other way round for Column 4. Problem: I´ve got a glimpse of an idea that MatLab doesn´t like, if i refer to a cell in the output column?! Do you have any other option to fill the cells with ones easier? Thanks very much!
  1 个评论
Jan
Jan 2017-12-13
编辑:Jan 2017-12-13
Please note that "cells" mean cell arrays in Matlab. Do you mean "element"?
After inspecting the picture, I have no idea what "That should be repeated other way round for Column 4" might mean. What is "e" and "a"? What does this mean:
I´ve got a glimpse of an idea that MatLab doesn´t like, if i
refer to a cell in the output column?
Do you get an error message?
"A2 and B7´s content" sounds, like you have an Excel problem. Does you question concern Matlab?

请先登录,再进行评论。

采纳的回答

Jan
Jan 2017-12-13
编辑:Jan 2017-12-13
Maybe you want this:
c1 = (X(:, 1) == 1);
c2 = (X(:, 2) == 1);
X(c2, 1) = -1;
X(c1, 2) = -1;
X(1, :) = max(X(1, :), 0);
Y = cumsum(X, 1);
Or:
match = find([any(X, 2), true]);
index = repelem(match(1:end-1), diff(match));
Y = X(index, :);
UNTESTED - please provide some inputs.
  1 个评论
Jonas Maurer
Jonas Maurer 2018-1-29
Thanks Jan Simon,
your tool fits my question. Thank you very much for that one. I also found a maybe more time consuming way which is seen below. But just to mention this way...
for m=range
if A(m,1) >= 0.9 && B(m,1)==0
C(m,1)=1;
else C(m,1)=0;
end
if C(m-1,1) >= 0.9 && B(m,1) <= 0.9
C(m,1)=1;
end
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by