Help with 3D Data Contour Plot (Missing Values as Zeros)
I’m working with a 3D data set in MATLAB where two planes (y1 and y3) have 65 rows and 4 columns each. The third plane (y2) has only 26 rows and 4 columns. I need to create a contour plot where missing values in y2 are treated as zeros. (raw data attached)
Desired Functionality:
All three planes (y1, y2, y3) should have the same number of rows for consistent plotting.
Missing points (represented by NaN) in y2 should be filled with zeros (treated as valid data for the contour plot).
The original data in y2 (including non-NaN values) should be preserved.
The contour plot should accurately represent the data in all three planes.
stack output three contour plots based on split y values apllied in a 3D Plot
rewrite the code. any help appreciated.
clear all
close all
clc
set(0,’DefaultaxesFontSize’,20);
set(0,’DefaulttextFontsize’,20);
set(0,’DefaultaxesFontName’,’Times-Roman’);
set(0,’DefaulttextFontName’,’Times-Roman’);
set(0,’defaulttextinterpreter’,’latex’)
set(0, ‘DefaultAxesLineWidth’, 4)
set(0,’DefaultAxesFontWeight’,’bold’)
set(gcf, ‘DefaultLineLineWidth’, 4)
set(gca, ‘DefaultLineLineWidth’, 4)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
T = readtable(‘HB2B_4298.csv’,’PreserveVariableNames’,true);%reading the data
Vx = table2array(T(:,:));%converting to arrays
TTT = Vx(:,11:14);%Pick your columns based on the data.EG., dsapce columns number = 13
A = unique(TTT,’rows’);
Acell = splitapply(@(x){x}, A,findgroups(A(:,2)));%split group based on column 2=vy
Acell{:};
y1 = [Acell{1,:}];%first plane values
y2 = [Acell{2,:}];%second plane values
y3 = [Acell{3,:}];%third plane values
% y4 = [Acell{4,:}];%fourth plane values
y = {y1, y2, y3};
N = length(y);
rg = cell(N,1); cg = cell(N,1);
Rg = cell(N,1); Cg = cell(N,1);
Zg = cell(N,1);
for i= 1:N
rg{i} = linspace(min(y{i}(:,1)), max(y{i}(:,1)), 100);%x axis
cg{i} = linspace(min(y{i}(:,3)), max(y{i}(:,3)), 100);%z axis
[Rg{i}, Cg{i}] = meshgrid(rg{i}, cg{i});% x and z
Zg{i} = griddata(y{i}(:,1), y{i}(:,3), y{i}(:,4), Rg{i}, Cg{i});%important change acoriding to data
h = figure
% subplot(N,1,i);
[CC,HH]= contourf(Rg{i}, Cg{i}, Zg{i});%plot contour
set(HH,’LineColor’,’none’)
colormap("default");
BB = colorbar
BB.Label.String = ‘d spacing’;%change
xlabel(‘X(mm)’)%change
ylabel(‘Z(mm)’)%change
saveas(h,sprintf(‘FIG%d.png’,i));%change the FIG name to whatever the name you need
% Create contour plot with transparency (adjust alpha value)
endI’m working with a 3D data set in MATLAB where two planes (y1 and y3) have 65 rows and 4 columns each. The third plane (y2) has only 26 rows and 4 columns. I need to create a contour plot where missing values in y2 are treated as zeros. (raw data attached)
Desired Functionality:
All three planes (y1, y2, y3) should have the same number of rows for consistent plotting.
Missing points (represented by NaN) in y2 should be filled with zeros (treated as valid data for the contour plot).
The original data in y2 (including non-NaN values) should be preserved.
The contour plot should accurately represent the data in all three planes.
stack output three contour plots based on split y values apllied in a 3D Plot
rewrite the code. any help appreciated.
clear all
close all
clc
set(0,’DefaultaxesFontSize’,20);
set(0,’DefaulttextFontsize’,20);
set(0,’DefaultaxesFontName’,’Times-Roman’);
set(0,’DefaulttextFontName’,’Times-Roman’);
set(0,’defaulttextinterpreter’,’latex’)
set(0, ‘DefaultAxesLineWidth’, 4)
set(0,’DefaultAxesFontWeight’,’bold’)
set(gcf, ‘DefaultLineLineWidth’, 4)
set(gca, ‘DefaultLineLineWidth’, 4)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
T = readtable(‘HB2B_4298.csv’,’PreserveVariableNames’,true);%reading the data
Vx = table2array(T(:,:));%converting to arrays
TTT = Vx(:,11:14);%Pick your columns based on the data.EG., dsapce columns number = 13
A = unique(TTT,’rows’);
Acell = splitapply(@(x){x}, A,findgroups(A(:,2)));%split group based on column 2=vy
Acell{:};
y1 = [Acell{1,:}];%first plane values
y2 = [Acell{2,:}];%second plane values
y3 = [Acell{3,:}];%third plane values
% y4 = [Acell{4,:}];%fourth plane values
y = {y1, y2, y3};
N = length(y);
rg = cell(N,1); cg = cell(N,1);
Rg = cell(N,1); Cg = cell(N,1);
Zg = cell(N,1);
for i= 1:N
rg{i} = linspace(min(y{i}(:,1)), max(y{i}(:,1)), 100);%x axis
cg{i} = linspace(min(y{i}(:,3)), max(y{i}(:,3)), 100);%z axis
[Rg{i}, Cg{i}] = meshgrid(rg{i}, cg{i});% x and z
Zg{i} = griddata(y{i}(:,1), y{i}(:,3), y{i}(:,4), Rg{i}, Cg{i});%important change acoriding to data
h = figure
% subplot(N,1,i);
[CC,HH]= contourf(Rg{i}, Cg{i}, Zg{i});%plot contour
set(HH,’LineColor’,’none’)
colormap("default");
BB = colorbar
BB.Label.String = ‘d spacing’;%change
xlabel(‘X(mm)’)%change
ylabel(‘Z(mm)’)%change
saveas(h,sprintf(‘FIG%d.png’,i));%change the FIG name to whatever the name you need
% Create contour plot with transparency (adjust alpha value)
end I’m working with a 3D data set in MATLAB where two planes (y1 and y3) have 65 rows and 4 columns each. The third plane (y2) has only 26 rows and 4 columns. I need to create a contour plot where missing values in y2 are treated as zeros. (raw data attached)
Desired Functionality:
All three planes (y1, y2, y3) should have the same number of rows for consistent plotting.
Missing points (represented by NaN) in y2 should be filled with zeros (treated as valid data for the contour plot).
The original data in y2 (including non-NaN values) should be preserved.
The contour plot should accurately represent the data in all three planes.
stack output three contour plots based on split y values apllied in a 3D Plot
rewrite the code. any help appreciated.
clear all
close all
clc
set(0,’DefaultaxesFontSize’,20);
set(0,’DefaulttextFontsize’,20);
set(0,’DefaultaxesFontName’,’Times-Roman’);
set(0,’DefaulttextFontName’,’Times-Roman’);
set(0,’defaulttextinterpreter’,’latex’)
set(0, ‘DefaultAxesLineWidth’, 4)
set(0,’DefaultAxesFontWeight’,’bold’)
set(gcf, ‘DefaultLineLineWidth’, 4)
set(gca, ‘DefaultLineLineWidth’, 4)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
T = readtable(‘HB2B_4298.csv’,’PreserveVariableNames’,true);%reading the data
Vx = table2array(T(:,:));%converting to arrays
TTT = Vx(:,11:14);%Pick your columns based on the data.EG., dsapce columns number = 13
A = unique(TTT,’rows’);
Acell = splitapply(@(x){x}, A,findgroups(A(:,2)));%split group based on column 2=vy
Acell{:};
y1 = [Acell{1,:}];%first plane values
y2 = [Acell{2,:}];%second plane values
y3 = [Acell{3,:}];%third plane values
% y4 = [Acell{4,:}];%fourth plane values
y = {y1, y2, y3};
N = length(y);
rg = cell(N,1); cg = cell(N,1);
Rg = cell(N,1); Cg = cell(N,1);
Zg = cell(N,1);
for i= 1:N
rg{i} = linspace(min(y{i}(:,1)), max(y{i}(:,1)), 100);%x axis
cg{i} = linspace(min(y{i}(:,3)), max(y{i}(:,3)), 100);%z axis
[Rg{i}, Cg{i}] = meshgrid(rg{i}, cg{i});% x and z
Zg{i} = griddata(y{i}(:,1), y{i}(:,3), y{i}(:,4), Rg{i}, Cg{i});%important change acoriding to data
h = figure
% subplot(N,1,i);
[CC,HH]= contourf(Rg{i}, Cg{i}, Zg{i});%plot contour
set(HH,’LineColor’,’none’)
colormap("default");
BB = colorbar
BB.Label.String = ‘d spacing’;%change
xlabel(‘X(mm)’)%change
ylabel(‘Z(mm)’)%change
saveas(h,sprintf(‘FIG%d.png’,i));%change the FIG name to whatever the name you need
% Create contour plot with transparency (adjust alpha value)
end contour, 3d plots MATLAB Answers — New Questions