Plot from cell array
4 vues (au cours des 30 derniers jours)
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
0 commentaires
Réponses (1)
Adam Danz
le 25 Avr 2021
Modifié(e) : Adam Danz
le 27 Avr 2021
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)
0 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!