How to plot data from a table that is in a cell array?
15 views (last 30 days)
Show older comments
I want to plot multiple curves to a single plot in a for loop. My data is stored in tables within a cell array. How can I do this? Here is what I have so far.
%DSC Data Subtract Function adn Plotter
%This file was designed to read raw DSC data from a text file and then
%perform a series of operations then plot it.
clear,clc;
format long
[file,path] = uigetfile('*.txt*',...
'Select One or More Files (MUST BE TEXT FILE)', ...
'MultiSelect', 'on');
% opts = detectImportOptions("DSC Script\DSC_Test.txt");
% opts.DataLines = [3 5];
%Put code that if the size if a file isnt choosen that the program ends (If
%file or path = 0 then end code)
degsign = char(0176);
TableArray = cell(length(file),1);
fileID = zeros(length(file));
%Create if statement for the instance if the number of files is one
if path == 0
message = 'You did not make a valid selection or canceled the dialog box. Please rerun the code with the proper selection';
title = "ERROR!"
f = msgbox(message,title)
elseif ischar(file) == 0
for i = 1 : length(file)
FileName = file{i};
fileID(i,1) = fopen(FileName);
T = readtable(FileName,"PreserveVariableNames",true);%Creates table from the data in the text file
TNew = removevars(T,{'Var1'}); % Removes Var Colum from Data as it is unnecessary
TNew = rmmissing(TNew);%Removes NaN values from the table and now the data is prepared for use and manipulation.
HFlo = TNew{:,"Unsubtracted_2"} - TNew{:,"Baseline_2"};
WeightPercent = (TNew{:,"Unsubtracted"}./TNew{1,"Unsubtracted"}).*100;
TNew = addvars(TNew,HFlo,'Before','Heat Flow');
TNew = addvars(TNew,WeightPercent,'Before',"Unsubtracted");
TableArray{i} = TNew;
plot(TNew.Sample,TNew.HFlo)
title(FileName)
xlabel('Temperature °C' )
ylabel('Heat Flow mW/mg')
figure
plot(TNew.Sample,TNew.WeightPercent)
title(FileName)
xlabel('Temperature °C' )
ylabel('Weight %')
figure
end
elseif ischar(file) == 1
fileID = fopen(file);
T = readtable(file,"PreserveVariableNames",true);
TNew = removevars(T,{'Var1'});
TNew = rmmissing(TNew);
HFlo = TNew{:,"Unsubtracted_2"} - TNew{:,"Baseline_2"};
WeightPercent = (TNew{:,"Unsubtracted"}./TNew{1,"Unsubtracted"}).*100;
TNew = addvars(TNew,HFlo,'Before','Heat Flow');
TNew = addvars(TNew,WeightPercent,'Before',"Unsubtracted");
plot(TNew.Sample,TNew.HFlo)
title(FileName)
xlabel('Temperature °C' )
ylabel('Heat Flow mW/mg')
figure;
plot(TNew.Sample,TNew.WeightPercent)
title(FileName)
xlabel('Temperature °C' )
ylabel('Weight %')
end
Maybe I approached this problem initally wrong.
Thank you for you help!
0 Comments
Answers (1)
See Also
Categories
Find more on Line 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!