Plot from cell array

4 次查看(过去 30 天)
Isai Fernandez
Isai Fernandez 2021-4-25
编辑: Adam Danz 2021-4-27
I want to plot data from cell array. I tried many ways, and I can't get it. I used plot inside and outside the loop, also scatter and stackedplot.
clc; clear variables; close all;
% Pregunta 01
filename='Test_Specimen_2.txt';
D = readtable('Test_Specimen_2.txt',...
'Range','A10:AN76',...
'ReadVariableNames',true);
i=1;
while i<=size(D,2)/2
d1 = D(:,2*i);
d2 = D(:,2*i-1);
D1{i} = [d1 d2];
i=i+1;
end
i=1;
while i<= size(D1,2)
stackedplot(D1{i},{'STRAIN','STRESS'});
hold on
i=i+1;
end

回答(1 个)

Adam Danz
Adam Danz 2021-4-25
编辑:Adam Danz 2021-4-27
It looks like you're trying to create a stackedplot with 2 lines per axes which is demonstrated here:
Instead of grouping columns of data in cell arrays, you just need to group the variable names together. It appears you want the lines to be grouped as [Var2, Var1], [Var4, Var3], [Var6, Var5], etc. Here's how to achieve that with stackedplot.
D = array2table(rand(10,8)); % demo table
varPairs = [D.Properties.VariableNames(2:2:end)', ...
D.Properties.VariableNames(1:2:end)'];
pairedVars = arrayfun(@(r){varPairs{r,:}},1:size(varPairs,1),'UniformOutput',false)'; %#ok<CCAT1>
stackedplot(D,pairedVars)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by