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!
답변 (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일
Brave A
2020년 11월 21일
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일
Brave A
2020년 11월 21일
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일
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일
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일
Brave A
2020년 11월 21일
Rik
2020년 11월 21일
Judging from this data you can use cumsum to make the plot you described.
Brave A
2020년 11월 21일
Brave A
2020년 11월 21일
카테고리
도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


