5 views (last 30 days)

dpb
on 11 Dec 2019

Edited: dpb
on 11 Dec 2019

Well, still kinda' difficult to figure out exactly what is wanted, but as near as I can make out, something like;

t=readtable('file.txt'); % read the file

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

dpb
on 11 Dec 2019

That's what my Answer above does except I thought you also wanted the first n consecutively, not just n at random.

Change the above to

ix=randperm(N,n);

Would have thought that obvious.

Set the xlim range as desired.

Walter Roberson
on 11 Dec 2019

dpb
on 11 Dec 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... :)

Sign in to comment.

Bandar Aldhafeeri
on 11 Dec 2019

Assume data stored in this form

1 23

2 34

3 54

The code is

file = load('data.txt');

n=3;

x=file(randi(10,1,n),1); % 10:max 1:min n: points number

y=file(x,2);

stem(x,y)

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 8 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776682

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776682

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776689

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776689

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776696

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776696

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776701

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776701

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776703

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776703

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776706

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776706

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776710

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776710

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776712

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/495971-plot-with-points-in-file#comment_776712

Sign in to comment.