You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to plot data contains only ones?
1 view (last 30 days)
Show older comments
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!
Answers (1)
KALYAN ACHARJYA
on 21 Nov 2020
Edited: KALYAN ACHARJYA
on 21 Nov 2020
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 Comments
KALYAN ACHARJYA
on 21 Nov 2020
Edited: KALYAN ACHARJYA
on 21 Nov 2020
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,'*');
KALYAN ACHARJYA
on 21 Nov 2020
Edited: KALYAN ACHARJYA
on 21 Nov 2020
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);
Rik
on 21 Nov 2020
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.
Brave A
on 21 Nov 2020
Edited: Brave A
on 21 Nov 2020
So I have 300 users and only 276 from got selected as ones and the rest is 0 . So I need to represent this selection in y-axis and relate each one to the user number select. Thanks in advance!
KALYAN ACHARJYA
on 21 Nov 2020
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)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)