How to plot data contains only ones?

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!

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 21 de Nov. de 2020
Editada: KALYAN ACHARJYA el 21 de Nov. de 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 comentarios

Brave A
Brave A el 21 de Nov. de 2020
Thanks for your answer, but I have those ones in text file, how to import it in your code?
Brave A
Brave A el 21 de Nov. de 2020
I don't want them in straight line (horizontal). Any suggestions to represent them?
KALYAN ACHARJYA
KALYAN ACHARJYA el 21 de Nov. de 2020
Editada: KALYAN ACHARJYA el 21 de Nov. de 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,'*');
Brave A
Brave A el 21 de Nov. de 2020
it covers all the figure. How to reduce the size?
Brave A
Brave A el 21 de Nov. de 2020
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
KALYAN ACHARJYA el 21 de Nov. de 2020
Editada: KALYAN ACHARJYA el 21 de Nov. de 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);
Brave A
Brave A el 21 de Nov. de 2020
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
Rik el 21 de Nov. de 2020
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
Brave A el 21 de Nov. de 2020
It did not works. Is there any way to relate them with x axes values so I can get desired plot?
Rik
Rik el 21 de Nov. de 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
Brave A el 21 de Nov. de 2020
Editada: Brave A el 21 de Nov. de 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!
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)
Brave A
Brave A el 21 de Nov. de 2020
Editada: Brave A el 21 de Nov. de 2020
this is not what I want .
Rik
Rik el 21 de Nov. de 2020
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
Brave A el 21 de Nov. de 2020
Sure! Here is the dataset contains 1 for selected users and 0 for nonselected. Thanks in advance!
Brave A
Brave A el 21 de Nov. de 2020
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.
Rik
Rik el 21 de Nov. de 2020
Judging from this data you can use cumsum to make the plot you described.
Brave A
Brave A el 21 de Nov. de 2020
I have another data set same like this how to plot with cumsum? because it's combiened then in one line.
Brave A
Brave A el 21 de Nov. de 2020
I think I got what I need ! Big thanks both of you.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 21 de Nov. de 2020

Comentada:

el 21 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by