How to plot table T such that column R is for X-axis and column I is for Y-axis and column V is the values between them? (I need to change the shape of dots according to V value such that if it is more than 4.5 for example it plots dot else it is *)

3 views (last 30 days)
R I V
_____ ______ _______
1000 0.0001 4.901
2000 0.0001 4.802
3000 0.0001 4.703
4000 0.0001 4.604
5000 0.0001 4.505
6000 0.0001 4.4059
7000 0.0001 4.3069
8000 0.0001 4.2079
9000 0.0001 4.1089
10000 0.0001 4.0099
the table has 100 points such that I is from 0.0001 to 0.001 with a 0.0001 increment
and R is as shown from 1k to 10k with 1k increment for each I value

Answers (1)

Benjamin Kraus
Benjamin Kraus on 31 Dec 2023
You cannot use two different markers on a single line, so your best bet is two overlapping lines, and you can use MarkerIndices to control which vertices on your line use markers. For example:
R = 1000:1000:10000;
I = 0.0001*ones(size(R));
V = [4.901, 4.802, 4.703, ...
4.604, 4.505, 4.4059, ...
4.3069, 4.2079, 4.1089, 4.0099];
tbl = table(R,I,V);
% Plot the same line twice
p = plot(tbl.R,tbl.I,tbl.R,tbl.I);
% The first line will have a solid line style, dot markers, and use
% MarkerIndices to control which vertices have markers.
p(1).LineStyle = '-';
p(1).Marker = '.';
p(1).MarkerIndices = find(tbl.V>4.5);
% The second line will have no line style, * markers, and use
% MarkerIndices to control which vertices have markers.
p(2).Color = p(1).Color;
p(2).LineStyle = 'none';
p(2).Marker = '*';
p(2).MarkerIndices = find(tbl.V<=4.5);
  1 Comment
Benjamin Kraus
Benjamin Kraus on 31 Dec 2023
Note, if you are using the lastest version of MATLAB, I would leverage two more recent features (table support in the plot command, and SeriesIndex) and write this code a little differently:
R = 1000:1000:10000;
I = 0.0001*ones(size(R));
V = [4.901, 4.802, 4.703, ...
4.604, 4.505, 4.4059, ...
4.3069, 4.2079, 4.1089, 4.0099];
tbl = table(R,I,V);
% Plot the same line twice, leveraging table support in the plot command
% added in R2022a.
p = plot(tbl, "R", ["I", "I"]);
% The first line will have a solid line style, dot markers, and use
% MarkerIndices to control which vertices have markers.
p(1).LineStyle = '-';
p(1).Marker = '.';
p(1).MarkerIndices = find(tbl.V>4.5);
% Make sure both lines use the same color by synchronizing their
% SeriesIndex.
p(2).SeriesIndex = p(1).SeriesIndex;
% The second line will have no line style, * markers, and use
% MarkerIndices to control which vertices have markers.
p(2).LineStyle = 'none';
p(2).Marker = '*';
p(2).MarkerIndices = find(tbl.V<=4.5);

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!