how to extract data from Matlab figure with stacked lines? (2024)

9 views (last 30 days)

Show older comments

Shaymaa Tahhan on 22 Feb 2024

  • Link

    Direct link to this question

    https://uk.mathworks.com/matlabcentral/answers/2085643-how-to-extract-data-from-matlab-figure-with-stacked-lines

  • Link

    Direct link to this question

    https://uk.mathworks.com/matlabcentral/answers/2085643-how-to-extract-data-from-matlab-figure-with-stacked-lines

Answered: Voss on 22 Feb 2024

  • intensity with lines.fig

Please I have tried alot with this code

open('spectrum.fig');

a = get(gca,'Children');

xdata = get(a, 'XData');

ydata = get(a, 'YData');

xdata1 = get(a(2), 'XData');

ydata1 = get(a(2), 'YData');

but it doesnt work correctly I just get the last line data?!

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (1)

Voss on 22 Feb 2024

  • Link

    Direct link to this answer

    https://uk.mathworks.com/matlabcentral/answers/2085643-how-to-extract-data-from-matlab-figure-with-stacked-lines#answer_1414768

  • Link

    Direct link to this answer

    https://uk.mathworks.com/matlabcentral/answers/2085643-how-to-extract-data-from-matlab-figure-with-stacked-lines#answer_1414768

  • intensity with lines.fig

f = openfig('intensity with lines.fig');

how to extract data from Matlab figure with stacked lines? (3)

lines = findall(f,'Type','line')

lines =

10×1 Line array: Line Line Line Line Line Line Line Line Line Line

xdata = get(lines,'XData'); % xdata: 10x1 cell array, each cell contains 1 line's XData

ydata = get(lines,'YData'); % ydata: 10x1 cell array, each cell contains 1 line's YData

If you know that the lines XData/YData are all row vectors of the same size (which they are in this case), it may be convenienet to concatentate them into a single matrix:

xdata = vertcat(xdata{:})

xdata = 10×8192

1.0e-11 * -0.6250 -0.6248 -0.6247 -0.6245 -0.6244 -0.6242 -0.6241 -0.6239 -0.6238 -0.6236 -0.6235 -0.6233 -0.6232 -0.6230 -0.6229 -0.6227 -0.6226 -0.6224 -0.6223 -0.6221 -0.6219 -0.6218 -0.6216 -0.6215 -0.6213 -0.6212 -0.6210 -0.6209 -0.6207 -0.6206 -0.6250 -0.6248 -0.6247 -0.6245 -0.6244 -0.6242 -0.6241 -0.6239 -0.6238 -0.6236 -0.6235 -0.6233 -0.6232 -0.6230 -0.6229 -0.6227 -0.6226 -0.6224 -0.6223 -0.6221 -0.6219 -0.6218 -0.6216 -0.6215 -0.6213 -0.6212 -0.6210 -0.6209 -0.6207 -0.6206 -0.6250 -0.6248 -0.6247 -0.6245 -0.6244 -0.6242 -0.6241 -0.6239 -0.6238 -0.6236 -0.6235 -0.6233 -0.6232 -0.6230 -0.6229 -0.6227 -0.6226 -0.6224 -0.6223 -0.6221 -0.6219 -0.6218 -0.6216 -0.6215 -0.6213 -0.6212 -0.6210 -0.6209 -0.6207 -0.6206 -0.6250 -0.6248 -0.6247 -0.6245 -0.6244 -0.6242 -0.6241 -0.6239 -0.6238 -0.6236 -0.6235 -0.6233 -0.6232 -0.6230 -0.6229 -0.6227 -0.6226 -0.6224 -0.6223 -0.6221 -0.6219 -0.6218 -0.6216 -0.6215 -0.6213 -0.6212 -0.6210 -0.6209 -0.6207 -0.6206 -0.6250 -0.6248 -0.6247 -0.6245 -0.6244 -0.6242 -0.6241 -0.6239 -0.6238 -0.6236 -0.6235 -0.6233 -0.6232 -0.6230 -0.6229 -0.6227 -0.6226 -0.6224 -0.6223 -0.6221 -0.6219 -0.6218 -0.6216 -0.6215 -0.6213 -0.6212 -0.6210 -0.6209 -0.6207 -0.6206 -0.6250 -0.6248 -0.6247 -0.6245 -0.6244 -0.6242 -0.6241 -0.6239 -0.6238 -0.6236 -0.6235 -0.6233 -0.6232 -0.6230 -0.6229 -0.6227 -0.6226 -0.6224 -0.6223 -0.6221 -0.6219 -0.6218 -0.6216 -0.6215 -0.6213 -0.6212 -0.6210 -0.6209 -0.6207 -0.6206 -0.6250 -0.6248 -0.6247 -0.6245 -0.6244 -0.6242 -0.6241 -0.6239 -0.6238 -0.6236 -0.6235 -0.6233 -0.6232 -0.6230 -0.6229 -0.6227 -0.6226 -0.6224 -0.6223 -0.6221 -0.6219 -0.6218 -0.6216 -0.6215 -0.6213 -0.6212 -0.6210 -0.6209 -0.6207 -0.6206 -0.6250 -0.6248 -0.6247 -0.6245 -0.6244 -0.6242 -0.6241 -0.6239 -0.6238 -0.6236 -0.6235 -0.6233 -0.6232 -0.6230 -0.6229 -0.6227 -0.6226 -0.6224 -0.6223 -0.6221 -0.6219 -0.6218 -0.6216 -0.6215 -0.6213 -0.6212 -0.6210 -0.6209 -0.6207 -0.6206 -0.6250 -0.6248 -0.6247 -0.6245 -0.6244 -0.6242 -0.6241 -0.6239 -0.6238 -0.6236 -0.6235 -0.6233 -0.6232 -0.6230 -0.6229 -0.6227 -0.6226 -0.6224 -0.6223 -0.6221 -0.6219 -0.6218 -0.6216 -0.6215 -0.6213 -0.6212 -0.6210 -0.6209 -0.6207 -0.6206 -0.6250 -0.6248 -0.6247 -0.6245 -0.6244 -0.6242 -0.6241 -0.6239 -0.6238 -0.6236 -0.6235 -0.6233 -0.6232 -0.6230 -0.6229 -0.6227 -0.6226 -0.6224 -0.6223 -0.6221 -0.6219 -0.6218 -0.6216 -0.6215 -0.6213 -0.6212 -0.6210 -0.6209 -0.6207 -0.6206

ydata = vertcat(ydata{:})

ydata = 10×8192

1.0e+00 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000

so that xdata(1,:) is the first line's XData, xdata(2,:) is the second line's XData, etc., etc.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABProgrammingProgramming Utilities

Find more on Programming Utilities in Help Center and File Exchange

Tags

  • data import
  • figure data import

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


how to extract data from Matlab figure with stacked lines? (4)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • 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)

Asia Pacific

Contact your local office

how to extract data from Matlab figure with stacked lines? (2024)
Top Articles
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 5979

Rating: 4.8 / 5 (58 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.