Effacer les filtres
Effacer les filtres

for loop saving a vector, not a value

1 vue (au cours des 30 derniers jours)
soloby
soloby le 13 Juin 2015
Commenté : Image Analyst le 13 Juin 2015
if i had
x = -10:0.1:10;
f1 = trapmf(x,[-2 0 0 2]);
how do i save the (x, f1) values of each iterations using the for loop?
I'm thinking it starts with something like
for
i = 1:length(x)
a = x(i);
b = f1(i);
end
but this will only give me a & b to be 1 value not a vector of length(x)

Réponse acceptée

Image Analyst
Image Analyst le 13 Juin 2015
How about
for i = 1:length(x)
a(i) = x(i);
b(i) = f1(i);
end
if you wanted/needed to assign a and b via a "for" loop?
  2 commentaires
soloby
soloby le 13 Juin 2015
that works. but i guess that's an unnecessary step since x and f1 are already the same thing.
Do you know of a way to divide my f1 function, which is a triangular wave, into 2 parts: values left of the peak and right of the peak?
thanks in advance.
Image Analyst
Image Analyst le 13 Juin 2015
I don't see why you say "x and f1 are already the same thing" but I don't have the fuzzy toolbox so I can't actually run trapmf().
To divide into two parts
[maxValue, indexAtMax] = max(b);
leftOfPeak = b(1 : indexAtMax-1);
rightOfPeak = b(indexAtMax+1 : end);
Note that the peak itself is not included in either of those arrays because you did not specify that it should be.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Fuzzy Inference System Modeling dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by