Plot with break in curve
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SHARAD KUMAR UPADHYAY
el 27 de Jul. de 2022
Comentada: SHARAD KUMAR UPADHYAY
el 27 de Jul. de 2022
%% 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.
Respuesta aceptada
Walter Roberson
el 27 de Jul. de 2022
Editada: Walter Roberson
el 27 de Jul. de 2022
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 comentarios
Walter Roberson
el 27 de Jul. de 2022
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(:));
Más respuestas (1)
Chunru
el 27 de Jul. de 2022
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
n = 11;
figure; hold on
for i=0:5
plot(xy(i*n+(1:n), 1), xy(i*n+(1:n), 2))
end
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!