i want to change the result in the following code that instead of result 1 2 3 4 5 give me a b c d e

3 visualizaciones (últimos 30 días)
for ii=1:(2000)
if ii>=1 && ii<=(400)
c(1,ii)=1;
else
if ii >=(401) && ii<=(800)
c(1,ii)=2;
else
if ii>=(801) && ii<=(1200)
c(1,ii)=3;
else
if ii>=(1201) && ii<=(1600)
c(1,ii)=4;
else
if ii>=(1601) && ii<=(2000)
c(1,ii)=5;
end
end
end
end
end
end
  1 comentario
Jan
Jan el 29 de Mayo de 2017
Editada: Jan el 29 de Mayo de 2017
EDITED, Code formatted. Please use the "{} Code" button by your own. Thanks.
Using parenthesis is not useful per se. There is no reason to include a 2000 in parenthesis.

Iniciar sesión para comentar.

Respuestas (3)

Jan
Jan el 29 de Mayo de 2017
The question is not clear. What is "a b c d e"?
A bold guess:
S = 'abcde';
Result = S(c);
  2 comentarios
Jan
Jan el 30 de Mayo de 2017
[EDITED, Moved from Answer section]
Alsadegh Mohamed wrote:
Thank you Jan Simon but the result of my program is as following from 1 to 400 is 1 and i want the result is a ----- and from 4001 to 800 is 2 and I want 2 ----- and from 8001 to 1200 is 3 and I want c ---- and from 1201 to 1600 is 4 and I want d ---- and from 1601 to 2000 is 5 and I want c ... i can not but a instead of 1 and b instead of 2 ..... So how can i get a b c d I mean how can put (a) instead of (1) ... without error
Jan
Jan el 30 de Mayo de 2017
"from 4001 to 800 is 2 and I want 2"? Do you mean 'b'?
I still think that my suggestion works. Did you try it? What do you observe?
The question is still not clear. Please create a small example of what you want, using Matlab syntax - do not use 400 but 2 elements.

Iniciar sesión para comentar.


Guillaume
Guillaume el 29 de Mayo de 2017
Tip: a bunch of if ... else statements is rarely a good way to solve problems.
The most straightforward way to obtain your vector would be:
c = repelem('abcde', 400)

Alsadegh Mohamed
Alsadegh Mohamed el 29 de Mayo de 2017
I want vector, its size 2000 the values in this vector from 1 to 400 is (a) and from 401 to 800 is (b) and from 801 to 1200 is (c) and from 1201 to 1600 is (d) and from 1601 to 2000 is (e) by for else if possible
  1 comentario
Guillaume
Guillaume el 29 de Mayo de 2017
Please use comments rather than creating new answers every time.
What is (a)? the character 'a' or something else. If you don't use valid matlab syntax, it's impossible to understand what you want.
My answer gives you a vector where the elements 1 to 400 are 'a', 401 to 800 is 'b', etc. It does so efficiently.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by