How to plot data contains only ones?
1 次查看(过去 30 天)
显示 更早的评论
Brave A
2020-11-21
Hi
How to plot data contains only ones?
I have txt file contains 1 1 1 1 1 1 only ones. and I want to represent it like
x-axis contains all user numbers
y-axis contains selected user where they represent it by : 1 ones. any suggestions to represent? bevause any time I tries I got line in the middle.
Thanks in advance!
回答(1 个)
KALYAN ACHARJYA
2020-11-21
编辑:KALYAN ACHARJYA
2020-11-21
user_number=20;
test_data=ones(1,user_number);
plot(1:user_number,test_data);
And yes, you definitely find the straight line (horizontal), because all the values of the y-axis are the same here. To load the data from text file, you can user load function with complete filename.
19 个评论
Brave A
2020-11-21
Thanks for your answer, but I have those ones in text file, how to import it in your code?
Brave A
2020-11-21
I don't want them in straight line (horizontal). Any suggestions to represent them?
KALYAN ACHARJYA
2020-11-21
编辑:KALYAN ACHARJYA
2020-11-21
load('file_test.txt');
% txt ^ sample file name
bar(file_test);
Since all the values are the same, the height of all the bars will be the same.
or
load('file_test.txt');
plot(file_test,'*');
Brave A
2020-11-21
What I need each '1' in y axis represent user number in x axis . so I need the line increases.
something like this.
KALYAN ACHARJYA
2020-11-21
编辑:KALYAN ACHARJYA
2020-11-21
To get such plot, the text data must be 1,2,3...or increment with any order
user_number=300;
test_data=1:300;
plot(1:user_number,test_data);
Brave A
2020-11-21
no, not this is what I want. I have the text file which contains 276 ones. Is there any way to relate them with x axes values so I can get desired plot?
Rik
2020-11-21
So you start of with this:
data=ones(276,1);
How do you want to determine x and y values? If you have to explain it in words?
Brave A
2020-11-21
It did not works. Is there any way to relate them with x axes values so I can get desired plot?
Rik
2020-11-21
You are not explaining how you are converting your data to a plot. Explain in words how you would find x and y points from your list of ones. I have no idea why you would not get a straight horizontal line. If you don't explain that, I can't help you.
KALYAN ACHARJYA
2020-11-21
For example, lets say, the user number is 5
user_num= [1 2 3 4 5];
select_da=[0 0 1 1 1]; % Just random example
plot(user_num,select_da)
Rik
2020-11-21
Can you share an example file? I suspect cumsum will do the trick for you, but I'm not sure, because you refuse to explain it with more words.
Brave A
2020-11-21
Sure! Here is the dataset contains 1 for selected users and 0 for nonselected. Thanks in advance!
Brave A
2020-11-21
I need to represent it in this way of containing 0 and 1 or only ones. Just need the reader to understand what is my results from figure.
Brave A
2020-11-21
I have another data set same like this how to plot with cumsum? because it's combiened then in one line.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)