230 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rose Sohyun Ahn am 2 Feb. 2022
Kommentiert: Dave B am 3 Feb. 2023
- hw1_kinetics.m
Hello,
I'm doing homework through matlab and I'm trying to find certain points that will fit my answer through matlab plotting. Is there a way I can click on the graph and extract x and y data points arbitrarily?
Thank you !
I have attached my very simple code for clarification.
1 Kommentar -1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Arif Hoq am 2 Feb. 2022
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/1641350-how-to-extract-data-points-from-a-plot#comment_1966535
It can be helpful
https://www.mathworks.com/matlabcentral/answers/100687-how-do-i-extract-data-from-matlab-figures
Melden Sie sich an, um zu kommentieren.
Melden Sie sich an, um diese Frage zu beantworten.
Antworten (1)
Dave B am 2 Feb. 2022
To interactively select points to export data to the workspace, there are a couple of options - using datatips is great for single points, data brushing works better for multiple points:
One point
For most MATLAB plots, you'll see a little box (called a datatip) when you hover over points. If you click while a point is highlighted, the box stays put when you move your mouse away. If you then right click you'll see an option to "Export Cursor Data to Workspace"
Multiple Points
When you hover over the axes a little toolbar shows up in the upper right corner. One of the options in that toolbar looks like a little paintbrush. Turn this on to activate "DataBrushing" mode. You can click and drag to select some points you'd like to export. When you've selected the points you want, disable brushing (by clicking the paintbrush again) and right click somewhere on the axes. You'll see an option to Export Brushed, which will export a variable containing the data points.
4 Kommentare 2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Rose Sohyun Ahn am 3 Feb. 2022
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/1641350-how-to-extract-data-points-from-a-plot#comment_1967665
how about data points between 3 and 4 let's say?
Dave B am 3 Feb. 2022
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/1641350-how-to-extract-data-points-from-a-plot#comment_1968485
Bearbeitet: Dave B am 3 Feb. 2022
Do you mean: how would you extract the set of data points programatically (i.e. not by clicking) from a line chart (i.e. made with the plot function) where x is between 3 and 4? You could query the XData and YData of the Line object like so:
x=linspace(0,5,50);
y=rand(size(x));
h=plot(x,y,'-o');
h.XData(h.XData >= 3 & h.YData <=4)
ans = 1×20
3.0612 3.1633 3.2653 3.3673 3.4694 3.5714 3.6735 3.7755 3.8776 3.9796 4.0816 4.1837 4.2857 4.3878 4.4898 4.5918 4.6939 4.7959 4.8980 5.0000
h.YData(h.XData >= 3 & h.YData <=4)
ans = 1×20
0.9329 0.7297 0.3868 0.1009 0.4098 0.5118 0.6134 0.7609 0.7607 0.7859 0.2555 0.4924 0.2036 0.9361 0.7540 0.6673 0.8542 0.7673 0.0565 0.6882
Ali am 20 Jan. 2023
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/1641350-how-to-extract-data-points-from-a-plot#comment_2574140
It works, thank you!
In the first method , can we get the x and y coordinates seperately instead of getting them in a [x,y] format?
further, there is also a column called "data index". is that related to the order of the data points?
does it indicate which data was plotted before the other one?
Dave B am 3 Feb. 2023
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/1641350-how-to-extract-data-points-from-a-plot#comment_2596376
@Ali -
I don't think there's a setting that will return the coordinates in separate variables, although it's pretty easy to move between vectors and variables.
x=cursor_info.Position(1);
y=cursor_info.Position(2);
If you had multiple datatips and wanted to grab all of them at once, you might do something like:
xy=vertcat(cursor_info.Position)
x=xy(:,1);y=xy(:,2);
Note that some plots (like surf or contour) might have a third dimension.
I think the DataIndex is the index into XData/YData properties, which corresponds to the order that you passed them into plot, but I'm not sure if that's your question. This might be a little more complicated if you don't have the "Snap to Nearest Data Vertex" option selected in Selection Style.
Melden Sie sich an, um zu kommentieren.
Melden Sie sich an, um diese Frage zu beantworten.
Siehe auch
Kategorien
MATLABGraphics2-D and 3-D Plots
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Tags
- plot
- data acquisition
Produkte
- MATLAB
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Es ist ein Fehler aufgetreten
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asien-Pazifik
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Kontakt zu Ihrer lokalen Niederlassung