How to plot arbitrary line slice against x or y axis in a table?
Show older comments
I have a data in a regular grid with x and y axis. I would like to extract any line slice of the data taken along x axis (in between two user defined y values) and plot it with respect to the appropriate x axis.
data = rand(5, 5);
x_axis = [5 6 7 8 9];
y_axis = [10.1 10.2 10.3 10.4 10.5]';
%Adding the x and y axis to the data
dataWithAxes = array2table(data,'VariableNames',string(x_axis), 'RowNames',string(y_axis));
% slicing the data for y = 10.1 in between x = 5 and x = 8
x_start='5'; x_end='8';
[X,Y] = ismember({x_start,x_end},dataWithAxes.Properties.VariableNames);
sliced_data = dataWithAxes('10.1',Y(1):Y(2))
How do I plot the sliced_data with its x values (which is [5 6 7 8])? I do not want to call the variable 'x_axis' as the axis information is already there in the variable 'sliced_data' and 'dataWithAxes'. Please suggest a soultion. Thank you.
Accepted Answer
More Answers (0)
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!