How to combine multiple columns of a table into one array to plot?
Show older comments
I am creating a table by reading through a file, the table contains the following:
Var1 Var2 Var3 Var4 Var5
9728.015877288 34.21601656 -85.26319543 6120.27 0.71
9728.100523585 34.19514296 -85.29652054 2121.33 2.60
9728.162613281 33.67647324 -83.90831590 2601.09 2.36
9728.178688810 34.17953039 -85.35196003 8092.13 4.57
9728.187776872 34.17839105 -85.35730262 8066.19 1.53
Var1 is time in seconds, and I am converting it to hh:mm:ss:SSS. Each row of the table is a "source" that contains the data Var1, Var2, Var3, Var4, Var5. I want to plot converted time vs source, where the user can input the ranges of each variable.
[FileName,PathName]=uigetfile(':','Select the LYLOUT file');
T=readtable(fullfile(PathName,FileName));
figure('units','normalized','outerposition',[0 0 1 1]);
prompt1 = {'(1) Enter the lower range of latitude where ' + string(min(T.Var2)) + ' is the minimum: ','(2) Enter upper range of latitude where ' + string(max(T.Var2)) + ' is the maximum: '};
dlgtitle1 = 'Latitude Range Input';
dims = [1 35];
answer1 = str2double(inputdlg(prompt1,dlgtitle1,dims));
prompt2 = {'(1) Enter the lower range of longitude where ' + string(min(T.Var3)) + ' is the minimum: ','(2) Enter upper range of longitude where ' + string(max(T.Var3)) + ' is the maximum: '};
dlgtitle2 = 'Longitude Range Input';
answer2 = str2double(inputdlg(prompt2,dlgtitle2,dims));
prompt3 = {'(1) Enter the lower range of altitude where ' + string(min(T.Var4)) + ' is the minimum: ','(2) Enter upper range of altitude where ' + string(max(T.Var4)) + ' is the maximum: '};
dlgtitle3 = 'Altitude Range Input';
answer3 = str2double(inputdlg(prompt3,dlgtitle3,dims));
prompt4 = {'(1) Enter the lower range of reduced chi squared where ' + string(min(T.Var5)) + ' is the minimum: ','(2) Enter upper range of reduced chi squared where ' + string(max(T.Var5)) + ' is the maximum: '};
dlgtitle4 = 'Reduced chi squared Range Input';
answer4 = str2double(inputdlg(prompt4,dlgtitle4,dims));
idx = T.Var2 >= answer1(1) & T.Var2 <= answer1(2) & T.Var3 >= answer2(1) & T.Var3 <= answer2(2) & T.Var4 >= answer3(1) & T.Var4 <= answer3(2) & T.Var5 >= answer4(1) & T.Var5 <= answer4(2);
timeUTC = seconds(T.Var1);
timeUTC.Format = 'hh:mm:ss.SSS';
plot(timeUTC(idx), [T.Var2(idx), T.Var3(idx), T.Var4(idx), T.Var5(idx)])
ylim([0 inf]);
grid minor;
xlabel('UTC Time');
ylabel('Sources');
title('Time vs Sources');
But instead of combining Var2, Var3, Var4 and Var5 into a variable it plots all of the variables at once. How would I plot the time vs source?
3 Comments
dpb
on 20 Apr 2020
"...instead of combining Var2, Var3, Var4 and Var5 into a variable..."
I don't understand...what does the above mean? You've selected a subset of the variables by user input and returned those selected subset variables. What would you expect to plot except four variables for that subset?
I don't see how you could combine four variables into one???
Can you show what a plot of what you envision would look like?
Mark Lupas
on 21 Apr 2020
dpb
on 21 Apr 2020
The (or at least one) problem is where does the time come for the subsequent channels--you've got 4X the variable data as the length of the time vector returned by the indexing operation. Are there four simultaneous measurements to plot as groups sequentially or what???
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots 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!