linkdata to structured data
7 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone,
i've got to vectors for example.
a= 1:20
b=a.^2;
If i plot with
plot(a,b) i am able to linkdata. But if i put These vectors in a struct: For example struct.x=a and struct.y =b, i can plot with plot(struct.x, struct.y).
But now it's not possible to linkdata here. The error Shows up in the figure: "No graphics have data sources. Cannot link plot: fix it".
Is it possible to link data to data located in a structure?
Thank you for your answers.
Rafael
0 件のコメント
採用された回答
Adam
2016 年 7 月 19 日
You can set the 'XDataSource' and 'YDataSource' of the line object to e.g myStruct.a and myStruct.b (never call a struct 'struct'!) either programmatically or via clicking on the line and editing properties.
2 件のコメント
Adam
2016 年 7 月 19 日
As far as I am aware you cannot link data in a surf plot.
You can do the equivalent just with programming though which is what I tend to do even for line plots - just update the 'XData', 'YData', 'ZData', 'CData' and any other appropriate properties of your line or surf object in response to data changing. Usually I would do this using listeners as updating a plot in the same function(s) where the data changes is an ugly solution.
その他の回答 (1 件)
Stephen23
2016 年 7 月 19 日
編集済み: Stephen23
2016 年 7 月 19 日
Solution
Yes it is possible, but you will have to either click the "Edit.." or "fix it" link in the figure, or by specifying those variables when the plot function is called:
>> S.a = 1:20;
>> S.b = S.a.^2;
>> plot(S.a,S.b,'XDataSource','S.a','YDataSource','S.b')
>> linkdata on
Explanation
The linkdata help states that it "compares variables in the current (base or function caller) workspace with the XData, YData, and ZData properties of graphs in the affected figure to try to match them. When a match is found, the appropriate XDataSource, YDataSource and/or ZDataSource for the graph are set to strings that name the matching variables."
Note that it does not recursively look inside those variables, it will only check and match simple numeric variables. But by providing S.a and S.b these are no longer variables but expressions containing the required data. MATLAB cannot match these to the structure fields because it does not do a recursive search inside any structures or cell arrays.
In any case, the most reliable way to use linkdata is to always specify the data source when calling the plot function, this means MATLAB does not need to search and match the variables in the workspace.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graphics Object Programming についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!