Is it possible to convert a function containing a plot into c++ code?

10 次查看(过去 30 天)
Hi! Is it possible to convert this function into c++? I would like to open a window in c++ that shows data as if I were in MATLAB.
%% INTERPOLAZIONE (distingue tratti rettilinei e curve e risoluzione impostabile)
function [Xq,Yq,Zq,Vq] = interpolazione(ampiezza,point_seabed_e,point_seabed_n,point_seabed_e_piu,point_seabed_n_piu,point_seabed_e_meno,point_seabed_n_meno,I,ris,metodo,mydir,folder,Namefile)
%% il comando griddata vuole come ingressi vettori colonne quindi trasformo le matrici di coordinate est e nord in vettori colonna
if(ampiezza==0)
points = [point_seabed_e(:),point_seabed_n(:),I(:)];
else
points = [point_seabed_e(:),point_seabed_n(:),I(:)
point_seabed_e_piu(:),point_seabed_n_piu(:),I(:)
point_seabed_e_meno(:),point_seabed_n_meno(:),I(:)];
end
%% Nuovi punti dove voglio valutare l'immagine
%calcolo i limiti entro cui fare l'interpolazione
% nord
Max_n = max(points(:,2));
Min_n = min(points(:,2));
v_sup=ceil(Max_n);
v_inf=floor(Min_n);
% est
Max_e = max(points(:,1));
Min_e = min(points(:,1));
u_sup=ceil(Max_e);
u_inf=floor(Min_e);
u=[u_inf:ris:u_sup];
v=[v_sup:-ris:v_inf];
[Xq,Yq] = meshgrid(u,v);
Zq=zeros(length(v),length(u));
%interpolazione
Vq = griddata(points(:,1),points(:,2),points(:,3),Xq,Yq,metodo);
% Plot immagine interpolata
close all
figure(1)
surf(Xq,Yq,Zq,Vq,'EdgeColor','none')
title(['Immagine interpolata con metodo ' metodo ' e risoluzione ' num2str(100*ris) ' cm'])
colormap gray
colorbar
caxis([0 1])
axis equal
xlabel('est (m)')
ylabel('nord (m)')
view(2)
[U,ia,ic] = unique([points(:,1) points(:,2)],'rows');
savefig(figure(1),fullfile(mydir,folder,Namefile),'compact');
end

回答(1 个)

Pratik
Pratik 2024-2-14
Hi Valeria,
As per my understanding, you want to convert your MATLAB function to C++ code so that data can be presented in same manner as it gets displayed in MATLAB but from C++ code.
To convert a MATLAB code to C++ code, MATLAB coder can be used. Alternatively to achieve same functionality as the MATLAB code from C++ interface, C++ Engine API can be used to call MATLAB function from C++ code.
Please refer to the documentation of MATLAB coder for more information:
Please refer to the documentation of C++ Engine API for more information on using the MATLAB C++ Engine API to call MATLAB from C++ programs:
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by