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 件のコメント
回答 (3 件)
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
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
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
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)
0 件のコメント
Alsadegh Mohamed
2017 年 5 月 29 日
1 件のコメント
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 Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!