Plot from cell array
Afficher commentaires plus anciens
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
Réponses (1)
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)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
