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

1 Ansicht (letzte 30 Tage)
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 Kommentare
dpb
dpb am 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.
Amanullah Khan
Amanullah Khan am 27 Feb. 2021
Yes mr. dpb, I have uploaded a plot_from_tables.m file where if all the (fuels(.mat) files) are kept in a folder. and if you select this folder it will draw the surface for all the fuels but with a common Parula colormap. Yes, i would like to have different color and also the name of the file to be displayed in figure.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 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 Kommentare
Amanullah Khan
Amanullah Khan am 1 Mär. 2021
Dear Mr. Roberson,
Sorry, I meant to say plot with surface fit. (plots with sfit)
The following syntaxes :
%% 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.
[fitresult, gof] = fit( [xData, yData], zData, ft );
%% Plot fit with data.
%subplot( 1,2,1);
h = plot( fitresult, [xData, yData], zData);
Regards,
Aman
Walter Roberson
Walter Roberson am 1 Mär. 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Linear and Nonlinear Regression finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by