Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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 commentaire
Jan
Jan le 13 Déc 2017
Modifié(e) : Jan le 13 Déc 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?

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 13 Déc 2017
Modifié(e) : Jan le 13 Déc 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 commentaire
Jonas Maurer
Jonas Maurer le 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by