Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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 Kommentar
Jan
Jan am 13 Dez. 2017
Bearbeitet: Jan am 13 Dez. 2017
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 13 Dez. 2017
Bearbeitet: Jan am 13 Dez. 2017
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 Kommentar
Jonas Maurer
Jonas Maurer am 29 Jan. 2018
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by