Plotting column of a matrix from a string.
Show older comments
I have a variable which contains data loaded from a matfile...
loadedContent=load('C:\Users\ringo\AppData\Local\Temp\temp3388979983628797436tmp\mv_20.mat');
in that matfile is a 360000x5 double called dat. I need to plot a column from dat using a char variable. I can plot all of the columns by creating a char variable
plotsall = 'dat';
plot(loadedContent.(num2str(plotsall)));
but if i try
plotcolumn = 'dat(:,1)';
plot(loadedContent.(num2str(plotcolumn)));
i get an error
Reference to non-existent field 'dat(:,1)'.
The only way round it I can think is to actually load the data into the workspace and plot using
plot(eval(plotcolumn));
this works, but using the eval function is never good... i just can't think of a way round it. Any ideas?
If you want/need anymore info as to why i'm doing this, a short version is making gui-->user locates file--->contents of file loaded into a list box--->user selects which data to plot--->if the data has more than one column a popup asks them which column to plot--->data gets plotted.
If you need anymore info, please let me know. Cheers
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!