필터 지우기
필터 지우기

How to plot data from a table that is in a cell array?

조회 수: 7 (최근 30일)
David Ramirez
David Ramirez 2020년 7월 1일
댓글: David Ramirez 2020년 7월 1일
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!

답변 (1개)

madhan ravi
madhan ravi 2020년 7월 1일
use hold on
  댓글 수: 1
David Ramirez
David Ramirez 2020년 7월 1일
I want both seperate plots of each data (why i use figure command) and one plot that has all combined.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by