Plot with break in curve

3 次查看(过去 30 天)
%% I am trying to plot using the command plot(x,y,'DisplayName','E'), by using the data as shown below:
%% x y
0.0000 -963.0477
0.0043 -961.9818
0.0085 -960.8602
0.0128 -959.6834
0.0171 -958.4515
0.0214 -957.1649
0.0256 -955.8239
0.0299 -954.4289
0.0342 -952.9801
0.0385 -951.4780
0.0427 -949.9230
0.0000 -863.7275
0.0043 -862.6394
0.0085 -861.4965
0.0128 -860.2993
0.0171 -859.0485
0.0214 -857.7448
0.0256 -856.3888
0.0299 -854.9813
0.0342 -853.5229
0.0385 -852.0146
0.0427 -850.4570
0.0000 -478.7403
0.0043 -478.0232
0.0085 -477.2695
0.0128 -476.4793
0.0171 -475.6530
0.0214 -474.7909
0.0256 -473.8934
0.0299 -472.9608
0.0342 -471.9935
0.0385 -470.9920
0.0427 -469.9565
0.0000 142.4990
0.0043 141.8359
0.0085 141.1374
0.0128 140.4037
0.0171 139.6348
0.0214 138.8308
0.0256 137.9917
0.0299 137.1176
0.0342 136.2085
0.0385 135.2646
0.0427 134.2860
0.0000 178.0669
0.0043 178.4201
0.0085 178.7855
0.0128 179.1619
0.0171 179.5483
0.0214 179.9436
0.0256 180.3468
0.0299 180.7566
0.0342 181.1720
0.0385 181.5916
0.0427 182.0144
0.0000 460.9589
0.0043 459.2786
0.0085 457.5096
0.0128 455.6524
0.0171 453.7071
0.0214 451.6741
0.0256 449.5538
0.0299 447.3464
0.0342 445.0524
0.0385 442.6722
0.0427 440.2061
%% Here data for x sxcale reeat from 0 to 0.0427 six times, when I plot, then a line I laos found form 0.0427 to 0.0000, and five lines I found in %%plot, I do not want to plot between these points or I don;t want these five lines, I wants to break curve after 0.427. Along with this, I also %%want to add horizontal line at 0.0128 and 0.0342 on x-axis and vertical line at 453.7071 on y-axis.

采纳的回答

Walter Roberson
Walter Roberson 2022-7-27
编辑:Walter Roberson 2022-7-27
data = [%% x y
0.0000 -963.0477
0.0043 -961.9818
0.0085 -960.8602
0.0128 -959.6834
0.0171 -958.4515
0.0214 -957.1649
0.0256 -955.8239
0.0299 -954.4289
0.0342 -952.9801
0.0385 -951.4780
0.0427 -949.9230
0.0000 -863.7275
0.0043 -862.6394
0.0085 -861.4965
0.0128 -860.2993
0.0171 -859.0485
0.0214 -857.7448
0.0256 -856.3888
0.0299 -854.9813
0.0342 -853.5229
0.0385 -852.0146
0.0427 -850.4570
0.0000 -478.7403
0.0043 -478.0232
0.0085 -477.2695
0.0128 -476.4793
0.0171 -475.6530
0.0214 -474.7909
0.0256 -473.8934
0.0299 -472.9608
0.0342 -471.9935
0.0385 -470.9920
0.0427 -469.9565
0.0000 142.4990
0.0043 141.8359
0.0085 141.1374
0.0128 140.4037
0.0171 139.6348
0.0214 138.8308
0.0256 137.9917
0.0299 137.1176
0.0342 136.2085
0.0385 135.2646
0.0427 134.2860
0.0000 178.0669
0.0043 178.4201
0.0085 178.7855
0.0128 179.1619
0.0171 179.5483
0.0214 179.9436
0.0256 180.3468
0.0299 180.7566
0.0342 181.1720
0.0385 181.5916
0.0427 182.0144
0.0000 460.9589
0.0043 459.2786
0.0085 457.5096
0.0128 455.6524
0.0171 453.7071
0.0214 451.6741
0.0256 449.5538
0.0299 447.3464
0.0342 445.0524
0.0385 442.6722
0.0427 440.2061];
x = reshape(data(:,1), 11, []);
y = reshape(data(:,2), 11, []);
x(12,:) = nan;
y(12,:) = nan;
plot(x(:), y(:));
xline([0.0128, 0.0342], 'k');
yline(453.7071, 'g');
  5 个评论
Walter Roberson
Walter Roberson 2022-7-27
For that data file, 0.0000 repeats every 11, not every 401. The entire file only has 66 data lines.
The following code tries to automatically detect the length before repetition.
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1079015/CO-ph-d.txt';
data = readmatrix(filename);
col1 = data(:,1);
repeatlength = find(col1(2:end) == col1(1), 1);
x = reshape(data(:,1), repeatlength, []);
y = reshape(data(:,2), repeatlength, []);
x(end+1,:) = nan;
y(end+1,:) = nan;
plot(x(:), y(:));
SHARAD KUMAR UPADHYAY
Last answer is also working, and this answer is more useful.

请先登录,再进行评论。

更多回答(1 个)

Chunru
Chunru 2022-7-27
xy=[0.0000 -963.0477
0.0043 -961.9818
0.0085 -960.8602
0.0128 -959.6834
0.0171 -958.4515
0.0214 -957.1649
0.0256 -955.8239
0.0299 -954.4289
0.0342 -952.9801
0.0385 -951.4780
0.0427 -949.9230
0.0000 -863.7275
0.0043 -862.6394
0.0085 -861.4965
0.0128 -860.2993
0.0171 -859.0485
0.0214 -857.7448
0.0256 -856.3888
0.0299 -854.9813
0.0342 -853.5229
0.0385 -852.0146
0.0427 -850.4570
0.0000 -478.7403
0.0043 -478.0232
0.0085 -477.2695
0.0128 -476.4793
0.0171 -475.6530
0.0214 -474.7909
0.0256 -473.8934
0.0299 -472.9608
0.0342 -471.9935
0.0385 -470.9920
0.0427 -469.9565
0.0000 142.4990
0.0043 141.8359
0.0085 141.1374
0.0128 140.4037
0.0171 139.6348
0.0214 138.8308
0.0256 137.9917
0.0299 137.1176
0.0342 136.2085
0.0385 135.2646
0.0427 134.2860
0.0000 178.0669
0.0043 178.4201
0.0085 178.7855
0.0128 179.1619
0.0171 179.5483
0.0214 179.9436
0.0256 180.3468
0.0299 180.7566
0.0342 181.1720
0.0385 181.5916
0.0427 182.0144
0.0000 460.9589
0.0043 459.2786
0.0085 457.5096
0.0128 455.6524
0.0171 453.7071
0.0214 451.6741
0.0256 449.5538
0.0299 447.3464
0.0342 445.0524
0.0385 442.6722
0.0427 440.2061];
whos
Name Size Bytes Class Attributes cmdout 1x33 66 char xy 66x2 1056 double
n = 11;
figure; hold on
for i=0:5
plot(xy(i*n+(1:n), 1), xy(i*n+(1:n), 2))
end

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by