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

2 ビュー (過去 30 日間)
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 件のコメント
Jan
Jan 2017 年 5 月 29 日
編集済み: Jan 2017 年 5 月 29 日
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.

サインインしてコメントする。

回答 (3 件)

Jan
Jan 2017 年 5 月 29 日
The question is not clear. What is "a b c d e"?
A bold guess:
S = 'abcde';
Result = S(c);
  2 件のコメント
Jan
Jan 2017 年 5 月 30 日
[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 2017 年 5 月 30 日
"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.

サインインしてコメントする。


Guillaume
Guillaume 2017 年 5 月 29 日
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 2017 年 5 月 29 日
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 件のコメント
Guillaume
Guillaume 2017 年 5 月 29 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by