Draw multiple surfaces from different tables(.mat) files. Such that the different .mat files have different Color and names should be displayed on the surface
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I would like to have to read multiple table (.mat) files from a folder and plot all the graphs in one figure like the rough diagram image I have attached. I have sent in the input files and the matlab code which runs all surfaces but does not have different color nor the names on the figure. I just want it easy to distinguish the the diffferent surfaces clearly.
Regards
Aman
2 Commenti
dpb
il 27 Feb 2021
So, what have you done and where, specifically, did you get stuck?
Appears all need to do is to define a color for each surface and apply that to each.
Risposte (1)
Walter Roberson
il 27 Feb 2021
I already gave you instructions on how to do this, but you did not follow the instructions.
Also, you did not deal with the fact that you had scattered data.
mat = dir('*.mat');
figure( 'Name', 'IDT VS PRESSURE AND TEMPERATURE' );
colormaps = {@parula, @turbo, @hsv, @hot, @cool, @spring, @summer, ...
@autumn, @winter, @gray, @bone, @copper, @pink, @jet, ...
@lines, @colorcube, @prism, @flag};
colormaps = colormaps(randperm(length(colormaps)));
N = 25;
for K = 1:length(mat)
load(mat(K).name);
table= table2array(Surface_table);
a =cell2mat(table(:,1)); %temperature
b =cell2mat (table(:,2)); %pressure
c = cell2mat( table(:,3)); %IDT
xd = double(a);
yd = double(b);
zd = double(c);
[Xg, Yg] = meshgrid(linspace(min(xd),max(xd),N), ...
linspace(min(yd),max(yd),N) );
F = scatteredInterpolant(xd, yd, zd);
Zg = F(Xg, Yg);
zdnor = (Zg-min(Zg(:)))/(max(Zg(:))-min(Zg(:)));
zdp = max(0, min(1, zdnor));
zres = zdp*(1-eps);
cmap = colormap(colormaps{K}());
cidx = floor(zres * size(cmap,1))+1;
zcol = reshape(cmap(cidx,:),size(Zg,1),size(Zg,2),3);
surf(Xg, Yg, Zg, 'edgecolor', 'none', 'CData', zcol)
hold on
end
hold off
This code clearly shows that you can apply different colormaps to different surfaces by scaling the z values into colormap indices and converting to RGB directly... just like I instructed before.
4 Commenti
Walter Roberson
il 1 Mar 2021
... I was supposed to just guess that you used surface fitting??
mat = dir('*.mat');
figure( 'Name', 'IDT VS PRESSURE AND TEMPERATURE' );
colormaps = {@parula, @turbo, @hsv, @hot, @cool, @spring, @summer, ...
@autumn, @winter, @gray, @bone, @copper, @pink, @jet, ...
@lines, @colorcube, @prism, @flag};
colormaps = colormaps(randperm(length(colormaps)));
N = 25;
for K = 1:length(mat)
thisfile = mat(K).name;
load(thisfile);
table= table2array(Surface_table);
a = cell2mat(table(:,1)); %temperature
b = cell2mat (table(:,2)); %pressure
c = cell2mat( table(:,3)); %IDT
% find polynomial surface fit
[xData, yData, zData] = prepareSurfaceData(b,a,c);
% Set up fittype and options.
ft = fittype( 'poly22' ); .............(This equation decides the degree of polynomial)
% Fit model to data.
[fr, gof] = fit( [xData, yData], zData, ft );
[Xg, Yg] = meshgrid(linspace(min(xData),max(xData),N), ...
linspace(min(yData),max(yData),N) );
Zg = fr.p00 + fr.p01 .* Xg + fr.p01 .* Yg + fr.p20 .* Xg.^2 + fr.p02 .* Yg.^2 + fr.p11 .* Xg .* Yg;
zdnor = (Zg-min(Zg(:)))/(max(Zg(:))-min(Zg(:)));
zdp = max(0, min(1, zdnor));
zres = zdp*(1-eps);
cmap = colormap(colormaps{K}());
cidx = floor(zres * size(cmap,1))+1;
zcol = reshape(cmap(cidx,:),size(Zg,1),size(Zg,2),3);
[~, basename, ~] = fileparts(thisfile);
surf(Xg, Yg, Zg, 'edgecolor', 'none', 'CData', zcol, 'DisplayName', basename)
hold on
end
hold off
legend show
Vedere anche
Categorie
Scopri di più su Fit Postprocessing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!