# plot with points in file

28 Ansichten (letzte 30 Tage)
Roger Nadal am 10 Dez. 2019
Kommentiert: dpb am 11 Dez. 2019
i have text file and have to create a function that will read a file which contain x and y cordinates for the data points and which will create a stem plot using n points random.
##### 8 Kommentare6 ältere Kommentare anzeigen6 ältere Kommentare ausblenden
Adam Danz am 10 Dez. 2019
I notice the x values are all positive integers - perhaps they are index values. If I remember correctly from your deleted question, you did not want the stem plots to all fall on integer values along the x axis. So, I guess my question is, once you read the x and y values in, are they simply the inputs to stem(x,y)?
Roger Nadal am 10 Dez. 2019
I am reading file using fopen but on x axis the points I want is total number of points in the file and after passing suppose n=20 it should plot 20 random points but the x axis should not changed

Melden Sie sich an, um zu kommentieren.

### Antworten (2)

dpb am 11 Dez. 2019
Bearbeitet: dpb am 11 Dez. 2019
Well, still kinda' difficult to figure out exactly what is wanted, but as near as I can make out, something like;
t=t(:,[2 4]); % get rid of the two x,y character columns
t.Properties.VariableNames={'x','y'}; % name two columns appropriately
% preliminaries out of way, the engine
nr=size(t,1); % rows in dataset
n=20; % arbitrary number points to plot initially and to choose randomly
ix=sort([1:n randperm(nr-n,n)+n]); % build the indexing vector of first n and n random thereafter
figure
stem(t.x(ix),t.y(ix)) % and stem() plot those...
QED
##### 20 Kommentare18 ältere Kommentare anzeigen18 ältere Kommentare ausblenden
Walter Roberson am 11 Dez. 2019
I would add an xlim([0 max(x)]) as otherwise the full x axis will not be displayed if the randomly chosen x locations are all less than 90.
dpb am 11 Dez. 2019
My understanding is he's actually wanting |xlim([0 x(end)]) regardless, so that's what I recommended above earlier.
But, expectations are so nebulous and getting information like pulling hens' teeth so I just said "salt to taste" this time...
Reminds of a DOE manager I worked for as consultant lo! those many years ago. I characterized working for him as being instructed "Bring me a rock!" When the rock was delivered, it was always "No, not that rock!" but could never say just which variety/size/shape/color of rock was desired until, finally, he either ran out of budget or (usually) would after third or fourth iteration suddenly decide the first or second was actually the one he was looking for after all... :)

Melden Sie sich an, um zu kommentieren.

Bandar am 11 Dez. 2019
Assume data stored in this form
1 23
2 34
3 54
The code is
n=3;
x=file(randi(10,1,n),1); % 10:max 1:min n: points number
y=file(x,2);
stem(x,y)
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Annotations finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by