Hello,
For my project, I would like to integrate a surf plot onto a GUI interface with a slider that update the plot inside the interface.
I tested the surf plot apart and it works fined but when i try to take the same structure as "Heatmap version" of the code that worked fine i got the error:
"Error using surf
Z must be a matrix, not a scalar or vector.
Error in TimeLapseInterpolatedMap (line 72)
heatObj = surf(uip,Vq);"
Of course, I understood that putting "iup" in the first argument of surf function doesn't work but then I don't know how to integrate it with my GUI.
Con you help me ?
Thank you !
% HEATMAP VERSION (WORKING)
data = M;
fig = uifigure();
uip = uipanel(fig,'Position', [20 100 500 300]);
heatObj = heatmap(uip, data(:,:,1),'Colormap', hsv,'CellLabelColor', 'none','ColorLimits', [-500 400]);
heatObj.Title = 'Electrode Fluorescence Heatmap - Frame 1';
n = size(data,3);
uis = uislider(fig,'Position',[50 50 450 3],...
'Value',1, ...
'Limits', [1,n], ...
'MajorTicks', 0:200:n, ...
'MinorTicks', []);
%valueChangedFcn for actualisation only when cursor is dropped
uis.ValueChangingFcn = {@sliderChangingFcn, data, heatObj};
function sliderChangingFcn(~,event,data,heatObj)
% Update heatmap and title with new selection of data
value = round(event.Value);
heatObj.ColorData = data(:,:,value);
heatObj.Title = sprintf('Electrode Fluorescence Heatmap - Frame #%d',value);
end
% SURF VERSION (NOT WORKING)
data = M;
fig = uifigure();
uip = uipanel(fig,'Position', [20 100 500 300]);
[Xq,Yq] = meshgrid(1:0.1:12);
Vq = interp2(data(:,:,1),Xq, Yq, 'cubic');
heatObj = surf(uip, Vq);
n = size(data,3);
uis = uislider(fig,'Position',[50 50 450 3],...
'Value',1, ...
'Limits', [1,n], ...
'MajorTicks', 0:200:n, ...
'MinorTicks', []);
%valueChangedFcn for actualisation only when cursor is dropped
uis.ValueChangingFcn = {@sliderChangingFcn, data, heatObj};
function sliderChangingFcn(~,event,data,heatObj)
% Update heatmap and title with new selection of data
value = round(event.Value);
heatObj.ColorData = data(:,:,value);
heatObj.Title = sprintf('Electrode Fluorescence Heatmap - Frame #%d',value);
end

Antworten (1)

Simon Chan
Simon Chan am 4 Okt. 2022

0 Stimmen

Create an uiaxes inside the uipanel or you can simply use uiaxes instead of uipanel inside the uifigure.

6 Kommentare

Julien Maxime
Julien Maxime am 4 Okt. 2022
Thank you it worked fine. Now do you know how to fix the range of Z (or colobar) through the updating of the cursos ? I tried zlim and clim command but made no differences.
Try the following and notice the comment below:
data = M;
fig = uifigure();
ax = uiaxes(fig,'Position', [20 100 500 300]); % Assume use uiaxes here
[Xq,Yq] = meshgrid(1:0.1:12);
Vq = interp2(data(:,:,1),Xq, Yq, 'cubic');
heatObj = surf(ax, Vq); % Draw on the uiaxes
n = size(data,3);
uis = uislider(fig,'Position',[50 50 450 3],...
'Value',1, ...
'Limits', [1,n], ...
'MajorTicks', 0:200:n, ...
'MinorTicks', []);
%valueChangedFcn for actualisation only when cursor is dropped
uis.ValueChangingFcn = {@sliderChangingFcn, data, heatObj, ax}; % Pass the axis handle as well
function sliderChangingFcn(~,event,data,heatObj,ax)
% Update heatmap and title with new selection of data
value = round(event.Value);
heatObj.ZData = data(:,:,value); % Update ZData also
heatObj.CData = data(:,:,value); % Update CData instead of ColorData
set(ax.Title,'String',sprintf('Electrode Fluorescence Heatmap - Frame #%d',value)); % Put the title on the axis instead of surf handle
end
You you gave me is displaying the raw matrix data and not the interpolated one. I modified it so it worked fine with interpolated data as the folloing:
But I still have the Color range that is modified at each update...
function sliderChangingFcn(~,event,data,heatObj)
% Update surf plot and title with new selection of data
value = round(event.Value);
Vq = interp2(data(:,:,value),Xq, Yq, 'cubic');
heatObj = surf(ax, Vq);
set(ax.Title,'String',sprintf('Electrode Fluorescence Heatmap - Frame #%d',value)); % Put the title on the axis instead of surf handle
end
Use function "caxis" to set your colormap limits
data = M;
fig = uifigure();
ax = uiaxes(fig,'Position', [20 100 500 300]);
[Xq,Yq] = meshgrid(1:0.1:12);
Vq = interp2(data(:,:,1),Xq, Yq, 'cubic');
heatObj = surf(ax, Vq);
n = size(data,3);
caxis(ax,[0 200]); % Use caxis and set your limits, example is 0 to 200
uis = uislider(fig,'Position',[50 50 450 3],...
'Value',1, ...
'Limits', [1,n], ...
'MajorTicks', 0:200:n, ...
'MinorTicks', []);
%valueChangedFcn for actualisation only when cursor is dropped
uis.ValueChangingFcn = {@sliderChangingFcn, data, heatObj, ax};
function sliderChangingFcn(~,event,data,heatObj,ax)
% Update heatmap and title with new selection of data
value = round(event.Value);
[Xq,Yq] = meshgrid(1:0.1:12);
Vq = interp2(data(:,:,value),Xq, Yq, 'cubic');
heatObj.ZData = Vq; % Use the same handle like this, no need to create a new one
heatObj.CData = Vq;
set(ax.Title,'String',sprintf('Electrode Fluorescence Heatmap - Frame #%d',value));
end
Julien Maxime
Julien Maxime am 4 Okt. 2022
Sorry I didnt expressed myself correctly I was looking to set the z value range. But your comment helped as I saw where to put a zlim (it put i previoulsy in the cursor loop which is useless).
Last question, do you know how to keep view point of the 3D graph during the cursor consecutives updates ? If not thank you, you already helped a lot.
Simon Chan
Simon Chan am 4 Okt. 2022
Are you looking for function view?
I don't have too much experience in 3D view and hence may not understand your needs, Sorry.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Line Plots finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 4 Okt. 2022

Kommentiert:

am 4 Okt. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by