Category: Matlab
Category Archives: Matlab
Library function log10 not found when using fit
I have been trying to fit some data using a lograthimic fit with the following command, where ind_array and sample_array are my x and y data respectively:
expo_curve=fit(ind_array,sample_array,’log10′);
However, I keep getting the following error:
Library function log10 not found.
The weird thing is I was using this exact code like 3 weeks ago and was able to generate the fit. So I am unsure what is going wrong, and the API says that ‘log10’ is a valid fittype for the fit command.
Any help would be appreciated,
Thank you,
SeanI have been trying to fit some data using a lograthimic fit with the following command, where ind_array and sample_array are my x and y data respectively:
expo_curve=fit(ind_array,sample_array,’log10′);
However, I keep getting the following error:
Library function log10 not found.
The weird thing is I was using this exact code like 3 weeks ago and was able to generate the fit. So I am unsure what is going wrong, and the API says that ‘log10’ is a valid fittype for the fit command.
Any help would be appreciated,
Thank you,
Sean I have been trying to fit some data using a lograthimic fit with the following command, where ind_array and sample_array are my x and y data respectively:
expo_curve=fit(ind_array,sample_array,’log10′);
However, I keep getting the following error:
Library function log10 not found.
The weird thing is I was using this exact code like 3 weeks ago and was able to generate the fit. So I am unsure what is going wrong, and the API says that ‘log10’ is a valid fittype for the fit command.
Any help would be appreciated,
Thank you,
Sean fit, curve fitting, log10 MATLAB Answers — New Questions
To plot one stem with multiple values for data of different months.
Dear MATLAB Experts,
I have data in .mat files, each corresponding to a particular month with selected_dates and brightness information.
Each month has a different number of output values (1, 2, 3, …, N). I need to create a stem plot for each month, with the month on the x-axis and brightness on the y-axis.
For example, if D201701 has six values, the plot will show six values in one single stem, and the x-axis will display the month name.
Additionally, I want to annotate each stem value with a marker (e.g., . or *) to indicate the corresponding date. I have attached an image that shows the stem plot for multiple values, as well as the data and code.
Thank you for guidance and help.Dear MATLAB Experts,
I have data in .mat files, each corresponding to a particular month with selected_dates and brightness information.
Each month has a different number of output values (1, 2, 3, …, N). I need to create a stem plot for each month, with the month on the x-axis and brightness on the y-axis.
For example, if D201701 has six values, the plot will show six values in one single stem, and the x-axis will display the month name.
Additionally, I want to annotate each stem value with a marker (e.g., . or *) to indicate the corresponding date. I have attached an image that shows the stem plot for multiple values, as well as the data and code.
Thank you for guidance and help. Dear MATLAB Experts,
I have data in .mat files, each corresponding to a particular month with selected_dates and brightness information.
Each month has a different number of output values (1, 2, 3, …, N). I need to create a stem plot for each month, with the month on the x-axis and brightness on the y-axis.
For example, if D201701 has six values, the plot will show six values in one single stem, and the x-axis will display the month name.
Additionally, I want to annotate each stem value with a marker (e.g., . or *) to indicate the corresponding date. I have attached an image that shows the stem plot for multiple values, as well as the data and code.
Thank you for guidance and help. plot, image analysis, signal processing, vector, matrices MATLAB Answers — New Questions
matlab fminsearch curve fitting HELP!!
I’m very new to Matlab and working on a code based on planck’s body radiation plots.
I’m trying to use fminsearch to estimate temperature from a set of three wavelength(x) and irradiance(y) data points. Temperature is the only parameter to be estimated, others are either xy data or constants.
My code is as follows:
c=2.997*10.^8; % m/s (speed of light)
h=6.6261*10.^-34; % J.s (planck’s constant)
k=1.38*10.^-23; % T/K (boltzmann’s constant)
xdata=[5.006e-07 5.104e-07 5.192e-07];
ydata=[3.223e+12 3.424e+12 3.606e+12];
figure(1)
clf
h1=plot(xdata,ydata,’ko’,’MarkerFaceColor’,’k’);
set(gca,’YLim’,[0,0.5*10^13]);
set(gca,’XLim’,[0.3*10^-6,0.7*10^-6]);
set(gca,’XTick’,xdata)
xlabel(‘Wavelength (m)’);
ylabel(‘Energy Density’);
t=3000;
pred = @(x,T) (c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1));
hold on
h2=plot(xdata,pred,’r-‘);
err = @(x,T) sum((((c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1))-ydata).^2);
T = fminsearch(@(x) err(xdata,x(1)),[3000]);
Please let me know where I’m wrong as I can’t figure it out.
Thanks.I’m very new to Matlab and working on a code based on planck’s body radiation plots.
I’m trying to use fminsearch to estimate temperature from a set of three wavelength(x) and irradiance(y) data points. Temperature is the only parameter to be estimated, others are either xy data or constants.
My code is as follows:
c=2.997*10.^8; % m/s (speed of light)
h=6.6261*10.^-34; % J.s (planck’s constant)
k=1.38*10.^-23; % T/K (boltzmann’s constant)
xdata=[5.006e-07 5.104e-07 5.192e-07];
ydata=[3.223e+12 3.424e+12 3.606e+12];
figure(1)
clf
h1=plot(xdata,ydata,’ko’,’MarkerFaceColor’,’k’);
set(gca,’YLim’,[0,0.5*10^13]);
set(gca,’XLim’,[0.3*10^-6,0.7*10^-6]);
set(gca,’XTick’,xdata)
xlabel(‘Wavelength (m)’);
ylabel(‘Energy Density’);
t=3000;
pred = @(x,T) (c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1));
hold on
h2=plot(xdata,pred,’r-‘);
err = @(x,T) sum((((c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1))-ydata).^2);
T = fminsearch(@(x) err(xdata,x(1)),[3000]);
Please let me know where I’m wrong as I can’t figure it out.
Thanks. I’m very new to Matlab and working on a code based on planck’s body radiation plots.
I’m trying to use fminsearch to estimate temperature from a set of three wavelength(x) and irradiance(y) data points. Temperature is the only parameter to be estimated, others are either xy data or constants.
My code is as follows:
c=2.997*10.^8; % m/s (speed of light)
h=6.6261*10.^-34; % J.s (planck’s constant)
k=1.38*10.^-23; % T/K (boltzmann’s constant)
xdata=[5.006e-07 5.104e-07 5.192e-07];
ydata=[3.223e+12 3.424e+12 3.606e+12];
figure(1)
clf
h1=plot(xdata,ydata,’ko’,’MarkerFaceColor’,’k’);
set(gca,’YLim’,[0,0.5*10^13]);
set(gca,’XLim’,[0.3*10^-6,0.7*10^-6]);
set(gca,’XTick’,xdata)
xlabel(‘Wavelength (m)’);
ylabel(‘Energy Density’);
t=3000;
pred = @(x,T) (c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1));
hold on
h2=plot(xdata,pred,’r-‘);
err = @(x,T) sum((((c.^2)*h.*pi.*2)./((x.^5).*(exp((h.*c)./(k.*x.*T))-1))-ydata).^2);
T = fminsearch(@(x) err(xdata,x(1)),[3000]);
Please let me know where I’m wrong as I can’t figure it out.
Thanks. fminsearch, blackbody, fit, curve fitting MATLAB Answers — New Questions
How to get dimensions of MATLABArray using MATLABEngine with .NET
When using a MathWorks.MATLAB.Types.MATLABArray, how do you get the dimensions of the array? I cannot find any properties that expose it.When using a MathWorks.MATLAB.Types.MATLABArray, how do you get the dimensions of the array? I cannot find any properties that expose it. When using a MathWorks.MATLAB.Types.MATLABArray, how do you get the dimensions of the array? I cannot find any properties that expose it. matlab, matlab compiler MATLAB Answers — New Questions
Mathematical Model To find transfer function
<</matlabcentral/answers/uploaded_files/1701611/Screenshot_20240522-200200%20(1).png>>
I need mathematical model for this can anyone help me with that using Simulink then to use that Simulink model to find transfer function<</matlabcentral/answers/uploaded_files/1701611/Screenshot_20240522-200200%20(1).png>>
I need mathematical model for this can anyone help me with that using Simulink then to use that Simulink model to find transfer function <</matlabcentral/answers/uploaded_files/1701611/Screenshot_20240522-200200%20(1).png>>
I need mathematical model for this can anyone help me with that using Simulink then to use that Simulink model to find transfer function simulink MATLAB Answers — New Questions
how to close a guide figure but close it without deleting the output struct
i have two files one being a fig set up with the guide and one that is suposed to take the fig file and use the user inputed numbers to calculate stuff.
the fig file creates a struct of said numbers and i can get the fig to run in the other script file but when i try and call on one of those numbers entered it says its trying to call on a deleted figure
function fpok_Callback(hObject, eventdata, handles)
%guidata(hObject,handles);
clc
% fpmcstr=string(get(handles.chkfpmc,’string’))
% fpcoystr=string(get(handles.chkfpcoy,’string’))
% fprgstr=string(get(handles.chkfprg,’string’))
% fpblkstr=string(get(handles.chkfpblk,’string’))
% fpmcbstr=string(get(handles.chkfpmcb,’string’))
% fparidstr=string(get(handles.chkfparid,’string’))
%
fpres=struct(‘fpmcqt’,0,’fpcoyqt’,0,’fprgqt’,0,’fpblkqt’,0,’fpmcbqt’,0,’fparidqt’,0);
if get(handles.chkfpmc,’Value’)
fpmcqt1=handles.fpmcqt.String;
fpres.fpmcqt=str2double(fpmcqt1)
end
if get(handles.chkfpcoy,’Value’)
fpcoyqt1=handles.fpcoyqt.String;
fpres.fpcoyqt=str2double(fpcoyqt1)
end
if get(handles.chkfprg,’Value’)
fprgqt1=handles.fprgqt.String;
fpres.fprgqt=str2double(fprgqt1)
end
if get(handles.chkfpblk,’Value’)
fpblkqt1=handles.fpblkqt.String;
fpres.fpblkqt=str2double(fpblkqt1)
end
if get(handles.chkfpmcb,’Value’)
fpmcbqt1=handles.fpmcbqt.String;
fpres.fpmcbqt=str2double(fpmcbqt1)
end
if get(handles.chkfparid,’Value’)
fparidqt1=handles.fparidqt.String;
fpres.fparidqt=str2double(fparidqt1)
end
handles.output=fpres;
%guidata(hObject,handles);
uiresume(ancestor(hObject, ‘figure’))
close()
%save(Flatpack, ‘fpres.FlatpackMC’)
when the ok button is puched this runs, and
fp=questdlg(‘Flatpacks’,’Select’,’Yes’,’No’,’c’);
switch fp
case ‘Yes’
fpres=Flatpack;
otherwise
fpres=struct(‘fpmcqt’,0,’fpcoyqt’,0,’fprgqt’,0,’fpblkqt’,0,’fpmcbqt’,0,’fparidqt’,0);
end
if ~ishandle(Flatpack)
fpmcqt=fpres.fpmcqt;
end
this is what i have in the other script to call the fig and the numbers entered in it. ther is only fpmcqt because i have been just testing the one to see if it can work.i have two files one being a fig set up with the guide and one that is suposed to take the fig file and use the user inputed numbers to calculate stuff.
the fig file creates a struct of said numbers and i can get the fig to run in the other script file but when i try and call on one of those numbers entered it says its trying to call on a deleted figure
function fpok_Callback(hObject, eventdata, handles)
%guidata(hObject,handles);
clc
% fpmcstr=string(get(handles.chkfpmc,’string’))
% fpcoystr=string(get(handles.chkfpcoy,’string’))
% fprgstr=string(get(handles.chkfprg,’string’))
% fpblkstr=string(get(handles.chkfpblk,’string’))
% fpmcbstr=string(get(handles.chkfpmcb,’string’))
% fparidstr=string(get(handles.chkfparid,’string’))
%
fpres=struct(‘fpmcqt’,0,’fpcoyqt’,0,’fprgqt’,0,’fpblkqt’,0,’fpmcbqt’,0,’fparidqt’,0);
if get(handles.chkfpmc,’Value’)
fpmcqt1=handles.fpmcqt.String;
fpres.fpmcqt=str2double(fpmcqt1)
end
if get(handles.chkfpcoy,’Value’)
fpcoyqt1=handles.fpcoyqt.String;
fpres.fpcoyqt=str2double(fpcoyqt1)
end
if get(handles.chkfprg,’Value’)
fprgqt1=handles.fprgqt.String;
fpres.fprgqt=str2double(fprgqt1)
end
if get(handles.chkfpblk,’Value’)
fpblkqt1=handles.fpblkqt.String;
fpres.fpblkqt=str2double(fpblkqt1)
end
if get(handles.chkfpmcb,’Value’)
fpmcbqt1=handles.fpmcbqt.String;
fpres.fpmcbqt=str2double(fpmcbqt1)
end
if get(handles.chkfparid,’Value’)
fparidqt1=handles.fparidqt.String;
fpres.fparidqt=str2double(fparidqt1)
end
handles.output=fpres;
%guidata(hObject,handles);
uiresume(ancestor(hObject, ‘figure’))
close()
%save(Flatpack, ‘fpres.FlatpackMC’)
when the ok button is puched this runs, and
fp=questdlg(‘Flatpacks’,’Select’,’Yes’,’No’,’c’);
switch fp
case ‘Yes’
fpres=Flatpack;
otherwise
fpres=struct(‘fpmcqt’,0,’fpcoyqt’,0,’fprgqt’,0,’fpblkqt’,0,’fpmcbqt’,0,’fparidqt’,0);
end
if ~ishandle(Flatpack)
fpmcqt=fpres.fpmcqt;
end
this is what i have in the other script to call the fig and the numbers entered in it. ther is only fpmcqt because i have been just testing the one to see if it can work. i have two files one being a fig set up with the guide and one that is suposed to take the fig file and use the user inputed numbers to calculate stuff.
the fig file creates a struct of said numbers and i can get the fig to run in the other script file but when i try and call on one of those numbers entered it says its trying to call on a deleted figure
function fpok_Callback(hObject, eventdata, handles)
%guidata(hObject,handles);
clc
% fpmcstr=string(get(handles.chkfpmc,’string’))
% fpcoystr=string(get(handles.chkfpcoy,’string’))
% fprgstr=string(get(handles.chkfprg,’string’))
% fpblkstr=string(get(handles.chkfpblk,’string’))
% fpmcbstr=string(get(handles.chkfpmcb,’string’))
% fparidstr=string(get(handles.chkfparid,’string’))
%
fpres=struct(‘fpmcqt’,0,’fpcoyqt’,0,’fprgqt’,0,’fpblkqt’,0,’fpmcbqt’,0,’fparidqt’,0);
if get(handles.chkfpmc,’Value’)
fpmcqt1=handles.fpmcqt.String;
fpres.fpmcqt=str2double(fpmcqt1)
end
if get(handles.chkfpcoy,’Value’)
fpcoyqt1=handles.fpcoyqt.String;
fpres.fpcoyqt=str2double(fpcoyqt1)
end
if get(handles.chkfprg,’Value’)
fprgqt1=handles.fprgqt.String;
fpres.fprgqt=str2double(fprgqt1)
end
if get(handles.chkfpblk,’Value’)
fpblkqt1=handles.fpblkqt.String;
fpres.fpblkqt=str2double(fpblkqt1)
end
if get(handles.chkfpmcb,’Value’)
fpmcbqt1=handles.fpmcbqt.String;
fpres.fpmcbqt=str2double(fpmcbqt1)
end
if get(handles.chkfparid,’Value’)
fparidqt1=handles.fparidqt.String;
fpres.fparidqt=str2double(fparidqt1)
end
handles.output=fpres;
%guidata(hObject,handles);
uiresume(ancestor(hObject, ‘figure’))
close()
%save(Flatpack, ‘fpres.FlatpackMC’)
when the ok button is puched this runs, and
fp=questdlg(‘Flatpacks’,’Select’,’Yes’,’No’,’c’);
switch fp
case ‘Yes’
fpres=Flatpack;
otherwise
fpres=struct(‘fpmcqt’,0,’fpcoyqt’,0,’fprgqt’,0,’fpblkqt’,0,’fpmcbqt’,0,’fparidqt’,0);
end
if ~ishandle(Flatpack)
fpmcqt=fpres.fpmcqt;
end
this is what i have in the other script to call the fig and the numbers entered in it. ther is only fpmcqt because i have been just testing the one to see if it can work. guide, matlab, gui, figure MATLAB Answers — New Questions
Compiling MEX Files without the mex Command
How can I compile MEX Files without the mex Command?How can I compile MEX Files without the mex Command? How can I compile MEX Files without the mex Command? mex, compile MATLAB Answers — New Questions
Textscan doesn’t work on big files?
I’m currently using the latest Matlab version on 16 GB RAM Mac.
I tried to perform a splitting of a really big cube file (100 GB) into smaller cube files with only 210151 lines per file using this code:
%% Splitting
% opening the result.cube file
fid = fopen(cube) ;
if fid == -1
error(‘File could not be opened.’);
end
m = 1 ;
while ~feof(fid)
% skip the alpha and beta density
fseek(fid,16596786,0) ;
% copy the spin density
text = textscan(fid,’%s’,210150,’Delimiter’,’n’,’Whitespace’,”) ;
% Prints the cube snap shot to the subdirectory
name = string(step_nr(m))+’.cube’ ;
full_path = fullfile(name1,name) ;
fid_new = fopen(full_path,"w") ;
fprintf(fid_new,’%sn’, text{1}{:}) ;
fclose(fid_new) ;
m = m+1 ;
end
fclose(fid) ;
save("steps","step_nr")
end
My problem is: Apparently, textscan is not suited for this kind of files. I also tried with line-by-line copying with fgetl, which on the other hand takes ages for a file of 100 GB. Is there a more efficient way to split the file?
I’ve read about fscanf and tried this:
tic;
fid = fopen(‘result.cube’);
fgetl(fid) ; fgetl(fid) ;
f = fscanf(fid, ‘%d %f %f %f’, [4 4]) ;
s = fscanf(fid, ‘%d %f %f %f %f’, [5 192]) ;
n = fscanf(fid, ‘%f %f %f %f %f %f’, [6 209953]) ;
fid_new = fopen("new",’w’) ;
fprintf(fid_new, ‘%d %.6f %.6f %.6fn’, f) ;
fprintf(fid_new, ‘%d %.6f %.6f %.6f %.6fn’, s) ;
fprintf(fid_new, ‘%f %f %f %f %fn’, n) ;
fclose(fid) ;
t=toc
But my problem here is: `s` is not aligned in the individual file like in the big file. `n` is in decimals instead of for example E-02. I also tried to copy it line by line but it takes years. Any suggestions how to improve this? I want it to look like this:I’m currently using the latest Matlab version on 16 GB RAM Mac.
I tried to perform a splitting of a really big cube file (100 GB) into smaller cube files with only 210151 lines per file using this code:
%% Splitting
% opening the result.cube file
fid = fopen(cube) ;
if fid == -1
error(‘File could not be opened.’);
end
m = 1 ;
while ~feof(fid)
% skip the alpha and beta density
fseek(fid,16596786,0) ;
% copy the spin density
text = textscan(fid,’%s’,210150,’Delimiter’,’n’,’Whitespace’,”) ;
% Prints the cube snap shot to the subdirectory
name = string(step_nr(m))+’.cube’ ;
full_path = fullfile(name1,name) ;
fid_new = fopen(full_path,"w") ;
fprintf(fid_new,’%sn’, text{1}{:}) ;
fclose(fid_new) ;
m = m+1 ;
end
fclose(fid) ;
save("steps","step_nr")
end
My problem is: Apparently, textscan is not suited for this kind of files. I also tried with line-by-line copying with fgetl, which on the other hand takes ages for a file of 100 GB. Is there a more efficient way to split the file?
I’ve read about fscanf and tried this:
tic;
fid = fopen(‘result.cube’);
fgetl(fid) ; fgetl(fid) ;
f = fscanf(fid, ‘%d %f %f %f’, [4 4]) ;
s = fscanf(fid, ‘%d %f %f %f %f’, [5 192]) ;
n = fscanf(fid, ‘%f %f %f %f %f %f’, [6 209953]) ;
fid_new = fopen("new",’w’) ;
fprintf(fid_new, ‘%d %.6f %.6f %.6fn’, f) ;
fprintf(fid_new, ‘%d %.6f %.6f %.6f %.6fn’, s) ;
fprintf(fid_new, ‘%f %f %f %f %fn’, n) ;
fclose(fid) ;
t=toc
But my problem here is: `s` is not aligned in the individual file like in the big file. `n` is in decimals instead of for example E-02. I also tried to copy it line by line but it takes years. Any suggestions how to improve this? I want it to look like this: I’m currently using the latest Matlab version on 16 GB RAM Mac.
I tried to perform a splitting of a really big cube file (100 GB) into smaller cube files with only 210151 lines per file using this code:
%% Splitting
% opening the result.cube file
fid = fopen(cube) ;
if fid == -1
error(‘File could not be opened.’);
end
m = 1 ;
while ~feof(fid)
% skip the alpha and beta density
fseek(fid,16596786,0) ;
% copy the spin density
text = textscan(fid,’%s’,210150,’Delimiter’,’n’,’Whitespace’,”) ;
% Prints the cube snap shot to the subdirectory
name = string(step_nr(m))+’.cube’ ;
full_path = fullfile(name1,name) ;
fid_new = fopen(full_path,"w") ;
fprintf(fid_new,’%sn’, text{1}{:}) ;
fclose(fid_new) ;
m = m+1 ;
end
fclose(fid) ;
save("steps","step_nr")
end
My problem is: Apparently, textscan is not suited for this kind of files. I also tried with line-by-line copying with fgetl, which on the other hand takes ages for a file of 100 GB. Is there a more efficient way to split the file?
I’ve read about fscanf and tried this:
tic;
fid = fopen(‘result.cube’);
fgetl(fid) ; fgetl(fid) ;
f = fscanf(fid, ‘%d %f %f %f’, [4 4]) ;
s = fscanf(fid, ‘%d %f %f %f %f’, [5 192]) ;
n = fscanf(fid, ‘%f %f %f %f %f %f’, [6 209953]) ;
fid_new = fopen("new",’w’) ;
fprintf(fid_new, ‘%d %.6f %.6f %.6fn’, f) ;
fprintf(fid_new, ‘%d %.6f %.6f %.6f %.6fn’, s) ;
fprintf(fid_new, ‘%f %f %f %f %fn’, n) ;
fclose(fid) ;
t=toc
But my problem here is: `s` is not aligned in the individual file like in the big file. `n` is in decimals instead of for example E-02. I also tried to copy it line by line but it takes years. Any suggestions how to improve this? I want it to look like this: data splitting MATLAB Answers — New Questions
How can I implement phased.freespace channel model outside matlab with moving target?
I would like to implement free space model in phased array toolbox outside matlab in order to do implementation in real time systems? There is an example in MATLAB to demonstrate moving targets. Lets say in this example how can I implement channel without matlab toolbox but with basic math operations.
Propagate Signal from Stationary Radar to Moving Target
https://www.mathworks.com/help/phased/ug/free-space-path-loss.html
Kind regards,
Oytun GUNESI would like to implement free space model in phased array toolbox outside matlab in order to do implementation in real time systems? There is an example in MATLAB to demonstrate moving targets. Lets say in this example how can I implement channel without matlab toolbox but with basic math operations.
Propagate Signal from Stationary Radar to Moving Target
https://www.mathworks.com/help/phased/ug/free-space-path-loss.html
Kind regards,
Oytun GUNES I would like to implement free space model in phased array toolbox outside matlab in order to do implementation in real time systems? There is an example in MATLAB to demonstrate moving targets. Lets say in this example how can I implement channel without matlab toolbox but with basic math operations.
Propagate Signal from Stationary Radar to Moving Target
https://www.mathworks.com/help/phased/ug/free-space-path-loss.html
Kind regards,
Oytun GUNES free space, path loss, moving target MATLAB Answers — New Questions
Does MATLAB’s installation files vary between different License Offerings?
Does MATLAB’s installation files vary between different License Offerings?Does MATLAB’s installation files vary between different License Offerings? Does MATLAB’s installation files vary between different License Offerings? MATLAB Answers — New Questions
parfeval with background pool fails when using Java classes
I’m trying to either use an existing database connection, based on com.mysql.cj.jdbc.Driver or to get that created in a parfeval call using the background worker.
Minimal examples using all the workarounds with and without function handles, parallel.pool.Constant(), external functions, etc.
db = com.mysql.cj.jdbc.Driver
fun1 = @()db.acceptsURL("asdf")
fun2 = @(db)db.acceptsURL("asdf")
fun3 = @(c)c.Value.acceptsURL("asdf")
C1 = parallel.pool.Constant(db);
getDriver = @()com.mysql.cj.jdbc.Driver;
C2 = parallel.pool.Constant(@getDriver);
C3 = parallel.pool.Constant(@getDriverExt);
fun1() % no error, direct call, outputs false
fun2(db) % no error, direct call, outputs false
fetchOutputs(parfeval(backgroundPool, fun1, 1)) % error serializing
fetchOutputs(parfeval(backgroundPool, fun2, 1, db)) % error serializing
fetchOutputs(parfeval(backgroundPool, fun3, 1, C1)) % error serializing, The ‘Value’ field cannot be retrieved because the parallel.pool.Constant is invalid.
fetchOutputs(parfeval(backgroundPool, fun3, 1, C2)) % Unrecognized function or variable ‘getDriver’.
fetchOutputs(parfeval(backgroundPool, fun3, 1, C3)) % Unable to resolve the name ‘com.mysql.cj.jdbc.Driver’.
getDriverExt.m
function conn = getDriverExt()
conn = com.mysql.cj.jdbc.Driver;
end
Here are the results of all runs:
>> fun1() % no error, direct call, outputs false
ans =
logical
0
>> fun2(db) % no error, direct call, outputs false
ans =
logical
0
>> fetchOutputs(parfeval(backgroundPool, fun1, 1)) % error serializing
Warning: com.mysql.cj.jdbc.Driver@3662c887 is not serializable
Error using parallel.BackgroundPool/parfeval
Internal error occurred when passing the input argument of type "function_handle" to the thread-based worker:
MATLAB:Serialize
Error during serialization
>> fetchOutputs(parfeval(backgroundPool, fun2, 1, db)) % error serializing
Warning: com.mysql.cj.jdbc.Driver@3662c887 is not serializable
Error using parallel.BackgroundPool/parfeval
Internal error occurred when passing the input argument of type "com.mysql.cj.jdbc.Driver" to the thread-based worker:
MATLAB:Serialize
Error during serialization
>> fetchOutputs(parfeval(backgroundPool, fun3, 1, C1)) % error serializing, The ‘Value’ field cannot be retrieved because the parallel.pool.Constant is invalid.
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Caused by:
Error using parallel.pool.Constant/get.Value (line 191)
The ‘Value’ field cannot be retrieved because the parallel.pool.Constant is invalid.
>> fetchOutputs(parfeval(backgroundPool, fun3, 1, C2)) % Unrecognized function or variable ‘getDriver’.
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Caused by:
Error using parallel.pool.Constant/get.Value (line 196)
Error occurred while creating parallel.pool.Constant on the workers.
Unrecognized function or variable ‘getDriver’.
>> fetchOutputs(parfeval(backgroundPool, fun3, 1, C3)) % Unable to resolve the name ‘com.mysql.cj.jdbc.Driver’.
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Caused by:
Error using parallel.pool.Constant/get.Value (line 196)
Error occurred while creating parallel.pool.Constant on the workers.
Unable to resolve the name ‘com.mysql.cj.jdbc.Driver’.
Is it impossible to use Java classes in the workers? If no, how to do it properly?
Thanks!I’m trying to either use an existing database connection, based on com.mysql.cj.jdbc.Driver or to get that created in a parfeval call using the background worker.
Minimal examples using all the workarounds with and without function handles, parallel.pool.Constant(), external functions, etc.
db = com.mysql.cj.jdbc.Driver
fun1 = @()db.acceptsURL("asdf")
fun2 = @(db)db.acceptsURL("asdf")
fun3 = @(c)c.Value.acceptsURL("asdf")
C1 = parallel.pool.Constant(db);
getDriver = @()com.mysql.cj.jdbc.Driver;
C2 = parallel.pool.Constant(@getDriver);
C3 = parallel.pool.Constant(@getDriverExt);
fun1() % no error, direct call, outputs false
fun2(db) % no error, direct call, outputs false
fetchOutputs(parfeval(backgroundPool, fun1, 1)) % error serializing
fetchOutputs(parfeval(backgroundPool, fun2, 1, db)) % error serializing
fetchOutputs(parfeval(backgroundPool, fun3, 1, C1)) % error serializing, The ‘Value’ field cannot be retrieved because the parallel.pool.Constant is invalid.
fetchOutputs(parfeval(backgroundPool, fun3, 1, C2)) % Unrecognized function or variable ‘getDriver’.
fetchOutputs(parfeval(backgroundPool, fun3, 1, C3)) % Unable to resolve the name ‘com.mysql.cj.jdbc.Driver’.
getDriverExt.m
function conn = getDriverExt()
conn = com.mysql.cj.jdbc.Driver;
end
Here are the results of all runs:
>> fun1() % no error, direct call, outputs false
ans =
logical
0
>> fun2(db) % no error, direct call, outputs false
ans =
logical
0
>> fetchOutputs(parfeval(backgroundPool, fun1, 1)) % error serializing
Warning: com.mysql.cj.jdbc.Driver@3662c887 is not serializable
Error using parallel.BackgroundPool/parfeval
Internal error occurred when passing the input argument of type "function_handle" to the thread-based worker:
MATLAB:Serialize
Error during serialization
>> fetchOutputs(parfeval(backgroundPool, fun2, 1, db)) % error serializing
Warning: com.mysql.cj.jdbc.Driver@3662c887 is not serializable
Error using parallel.BackgroundPool/parfeval
Internal error occurred when passing the input argument of type "com.mysql.cj.jdbc.Driver" to the thread-based worker:
MATLAB:Serialize
Error during serialization
>> fetchOutputs(parfeval(backgroundPool, fun3, 1, C1)) % error serializing, The ‘Value’ field cannot be retrieved because the parallel.pool.Constant is invalid.
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Caused by:
Error using parallel.pool.Constant/get.Value (line 191)
The ‘Value’ field cannot be retrieved because the parallel.pool.Constant is invalid.
>> fetchOutputs(parfeval(backgroundPool, fun3, 1, C2)) % Unrecognized function or variable ‘getDriver’.
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Caused by:
Error using parallel.pool.Constant/get.Value (line 196)
Error occurred while creating parallel.pool.Constant on the workers.
Unrecognized function or variable ‘getDriver’.
>> fetchOutputs(parfeval(backgroundPool, fun3, 1, C3)) % Unable to resolve the name ‘com.mysql.cj.jdbc.Driver’.
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Caused by:
Error using parallel.pool.Constant/get.Value (line 196)
Error occurred while creating parallel.pool.Constant on the workers.
Unable to resolve the name ‘com.mysql.cj.jdbc.Driver’.
Is it impossible to use Java classes in the workers? If no, how to do it properly?
Thanks! I’m trying to either use an existing database connection, based on com.mysql.cj.jdbc.Driver or to get that created in a parfeval call using the background worker.
Minimal examples using all the workarounds with and without function handles, parallel.pool.Constant(), external functions, etc.
db = com.mysql.cj.jdbc.Driver
fun1 = @()db.acceptsURL("asdf")
fun2 = @(db)db.acceptsURL("asdf")
fun3 = @(c)c.Value.acceptsURL("asdf")
C1 = parallel.pool.Constant(db);
getDriver = @()com.mysql.cj.jdbc.Driver;
C2 = parallel.pool.Constant(@getDriver);
C3 = parallel.pool.Constant(@getDriverExt);
fun1() % no error, direct call, outputs false
fun2(db) % no error, direct call, outputs false
fetchOutputs(parfeval(backgroundPool, fun1, 1)) % error serializing
fetchOutputs(parfeval(backgroundPool, fun2, 1, db)) % error serializing
fetchOutputs(parfeval(backgroundPool, fun3, 1, C1)) % error serializing, The ‘Value’ field cannot be retrieved because the parallel.pool.Constant is invalid.
fetchOutputs(parfeval(backgroundPool, fun3, 1, C2)) % Unrecognized function or variable ‘getDriver’.
fetchOutputs(parfeval(backgroundPool, fun3, 1, C3)) % Unable to resolve the name ‘com.mysql.cj.jdbc.Driver’.
getDriverExt.m
function conn = getDriverExt()
conn = com.mysql.cj.jdbc.Driver;
end
Here are the results of all runs:
>> fun1() % no error, direct call, outputs false
ans =
logical
0
>> fun2(db) % no error, direct call, outputs false
ans =
logical
0
>> fetchOutputs(parfeval(backgroundPool, fun1, 1)) % error serializing
Warning: com.mysql.cj.jdbc.Driver@3662c887 is not serializable
Error using parallel.BackgroundPool/parfeval
Internal error occurred when passing the input argument of type "function_handle" to the thread-based worker:
MATLAB:Serialize
Error during serialization
>> fetchOutputs(parfeval(backgroundPool, fun2, 1, db)) % error serializing
Warning: com.mysql.cj.jdbc.Driver@3662c887 is not serializable
Error using parallel.BackgroundPool/parfeval
Internal error occurred when passing the input argument of type "com.mysql.cj.jdbc.Driver" to the thread-based worker:
MATLAB:Serialize
Error during serialization
>> fetchOutputs(parfeval(backgroundPool, fun3, 1, C1)) % error serializing, The ‘Value’ field cannot be retrieved because the parallel.pool.Constant is invalid.
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Caused by:
Error using parallel.pool.Constant/get.Value (line 191)
The ‘Value’ field cannot be retrieved because the parallel.pool.Constant is invalid.
>> fetchOutputs(parfeval(backgroundPool, fun3, 1, C2)) % Unrecognized function or variable ‘getDriver’.
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Caused by:
Error using parallel.pool.Constant/get.Value (line 196)
Error occurred while creating parallel.pool.Constant on the workers.
Unrecognized function or variable ‘getDriver’.
>> fetchOutputs(parfeval(backgroundPool, fun3, 1, C3)) % Unable to resolve the name ‘com.mysql.cj.jdbc.Driver’.
Error using parallel.Future/fetchOutputs
One or more futures resulted in an error.
Caused by:
Error using parallel.pool.Constant/get.Value (line 196)
Error occurred while creating parallel.pool.Constant on the workers.
Unable to resolve the name ‘com.mysql.cj.jdbc.Driver’.
Is it impossible to use Java classes in the workers? If no, how to do it properly?
Thanks! java, matlab, parallel computing, parfeval, functions MATLAB Answers — New Questions
Almanac function not work
Dear Sir or Madam, I am a student, and I am preparing for tomorrow’s colloquium (partial exam for those who do not have the Bologna regime). I need to save a script for calculation, and it is based on the almanac function, which suddenly does not work! How can you help me, what should I use in exchange for alamance
Unrecognized function or variable ‘almanac’.
Error in ReferetnaPovrs (line 15) this.ref_pov=almanac("earth","bessel","meter");Dear Sir or Madam, I am a student, and I am preparing for tomorrow’s colloquium (partial exam for those who do not have the Bologna regime). I need to save a script for calculation, and it is based on the almanac function, which suddenly does not work! How can you help me, what should I use in exchange for alamance
Unrecognized function or variable ‘almanac’.
Error in ReferetnaPovrs (line 15) this.ref_pov=almanac("earth","bessel","meter"); Dear Sir or Madam, I am a student, and I am preparing for tomorrow’s colloquium (partial exam for those who do not have the Bologna regime). I need to save a script for calculation, and it is based on the almanac function, which suddenly does not work! How can you help me, what should I use in exchange for alamance
Unrecognized function or variable ‘almanac’.
Error in ReferetnaPovrs (line 15) this.ref_pov=almanac("earth","bessel","meter"); matlab, optimization, surface MATLAB Answers — New Questions
function where input is also output
Is it possible to have a function where the argument is also calculated in the same function?Is it possible to have a function where the argument is also calculated in the same function? Is it possible to have a function where the argument is also calculated in the same function? function, inputs, outputs MATLAB Answers — New Questions
Property Type in constructor vs dependent
I am using a function handle in a class and there seems to be a difference whether I set it in properties or in dependent properties. In the second case I need to add a cast to my property or else it doesn’t work.
There seems to be some type related thing I do not understand.
Thank you for your help!
Function
This is the function and it’s execution (in the class D_b is defined as a double):
D_b = 19;
f = @(t)(D_b/2)*(cos(t)+t.*sin(t));
x = f(linspace(0,pi/4,50)’);
Works without cast
When I define it in properties and initialize it via the constructor like below, it works:
properties(SetAccess=immutable, GetAccess=public)
% Base circle diameter
D_b double
% Involute function x axis
i_x function_handle
end
function obj = Spur()
%….
obj.D_b = 38; %Example
obj.i_x = @(t)(D_b/2)*(cos(t)+t.*sin(t));
%….
end
Fails without cast
When I try to use dependents it fails unless I cast D_b/2 to a double:
properties (Dependent)
D_b double
i_x function_handle
end
methods
function db = get.D_b(obj)
db = double(obj.D*cosd(obj.phiDegrees)); %CASTING
end
function ix = get.i_x(obj)
ix = @(t)(obj.D_b/2)*(cos(t)+t.*sin(t));
end
end
If I don’t cast the following error occures (which is not the case with my first approach):
Error using *
Integers can only be combined with integers of the same class, or scalar doubles.
Error in Spur>@(t)(obj.D_b/2)*(cos(t)+t.*sin(t)) (line 97)
ix = @(t)(obj.D_b/2)*(cos(t)+t.*sin(t));I am using a function handle in a class and there seems to be a difference whether I set it in properties or in dependent properties. In the second case I need to add a cast to my property or else it doesn’t work.
There seems to be some type related thing I do not understand.
Thank you for your help!
Function
This is the function and it’s execution (in the class D_b is defined as a double):
D_b = 19;
f = @(t)(D_b/2)*(cos(t)+t.*sin(t));
x = f(linspace(0,pi/4,50)’);
Works without cast
When I define it in properties and initialize it via the constructor like below, it works:
properties(SetAccess=immutable, GetAccess=public)
% Base circle diameter
D_b double
% Involute function x axis
i_x function_handle
end
function obj = Spur()
%….
obj.D_b = 38; %Example
obj.i_x = @(t)(D_b/2)*(cos(t)+t.*sin(t));
%….
end
Fails without cast
When I try to use dependents it fails unless I cast D_b/2 to a double:
properties (Dependent)
D_b double
i_x function_handle
end
methods
function db = get.D_b(obj)
db = double(obj.D*cosd(obj.phiDegrees)); %CASTING
end
function ix = get.i_x(obj)
ix = @(t)(obj.D_b/2)*(cos(t)+t.*sin(t));
end
end
If I don’t cast the following error occures (which is not the case with my first approach):
Error using *
Integers can only be combined with integers of the same class, or scalar doubles.
Error in Spur>@(t)(obj.D_b/2)*(cos(t)+t.*sin(t)) (line 97)
ix = @(t)(obj.D_b/2)*(cos(t)+t.*sin(t)); I am using a function handle in a class and there seems to be a difference whether I set it in properties or in dependent properties. In the second case I need to add a cast to my property or else it doesn’t work.
There seems to be some type related thing I do not understand.
Thank you for your help!
Function
This is the function and it’s execution (in the class D_b is defined as a double):
D_b = 19;
f = @(t)(D_b/2)*(cos(t)+t.*sin(t));
x = f(linspace(0,pi/4,50)’);
Works without cast
When I define it in properties and initialize it via the constructor like below, it works:
properties(SetAccess=immutable, GetAccess=public)
% Base circle diameter
D_b double
% Involute function x axis
i_x function_handle
end
function obj = Spur()
%….
obj.D_b = 38; %Example
obj.i_x = @(t)(D_b/2)*(cos(t)+t.*sin(t));
%….
end
Fails without cast
When I try to use dependents it fails unless I cast D_b/2 to a double:
properties (Dependent)
D_b double
i_x function_handle
end
methods
function db = get.D_b(obj)
db = double(obj.D*cosd(obj.phiDegrees)); %CASTING
end
function ix = get.i_x(obj)
ix = @(t)(obj.D_b/2)*(cos(t)+t.*sin(t));
end
end
If I don’t cast the following error occures (which is not the case with my first approach):
Error using *
Integers can only be combined with integers of the same class, or scalar doubles.
Error in Spur>@(t)(obj.D_b/2)*(cos(t)+t.*sin(t)) (line 97)
ix = @(t)(obj.D_b/2)*(cos(t)+t.*sin(t)); class, properties, casting, function handle, double MATLAB Answers — New Questions
Dutycycling Bluetooth Mesh Network
Hello everyone,
I found this Bluetooth Mesh simulation library and I’m very excited about it. I got a question regarding the energy profiling modeling. Is it somehow possible to add a dutycycle to the system simulation? Lets say the Bluetooth Radio is on for 10 seconds with ongoing network communication and then turned of for the next 20 seconds before this cycle repeats itself. I was planning to do so in my application with synchronized mesh nodes and it would be awesome to integrate this behavior in this system model.
Regards,
BjoernHello everyone,
I found this Bluetooth Mesh simulation library and I’m very excited about it. I got a question regarding the energy profiling modeling. Is it somehow possible to add a dutycycle to the system simulation? Lets say the Bluetooth Radio is on for 10 seconds with ongoing network communication and then turned of for the next 20 seconds before this cycle repeats itself. I was planning to do so in my application with synchronized mesh nodes and it would be awesome to integrate this behavior in this system model.
Regards,
Bjoern Hello everyone,
I found this Bluetooth Mesh simulation library and I’m very excited about it. I got a question regarding the energy profiling modeling. Is it somehow possible to add a dutycycle to the system simulation? Lets say the Bluetooth Radio is on for 10 seconds with ongoing network communication and then turned of for the next 20 seconds before this cycle repeats itself. I was planning to do so in my application with synchronized mesh nodes and it would be awesome to integrate this behavior in this system model.
Regards,
Bjoern mesh, bluetooth MATLAB Answers — New Questions
.MAT FILES AND WRITING CODE TO ANALYSE THE .MAT FILES
Hello everyone. i am going to try give you as much information as possible. i know it may seem like a simple question but i am ripping my hair out.
ok so my original txt file has over 3000 rows of data and 5 columns.i have written a code that goes through the time (column 2) and identifies a change. That change in time corresponds to the start of a new test. For the original text file i found i have 3 tests, hence, 3 .mat files that i have saved using the following script. Each .mat file has 3 columns and multiple rows and each .mat file corresponds to a seperate test (like i mentioned). the columns are x,y, test condition 1 -18 etc.
pts = findchangepts(data(:,2), ‘Statistic’, ‘linear’, ‘MinThreshold’,100)
pts(end+1) = finalrow;
num_step = data(:,1)
x = data(:,4);
y = data(:,5);
fin = 1;
next = 1;
while(fin)
% make seperate files for the tests.
for i=1:length(pts)
matrix = [x(next:pts(i,:)), y(next:pts(i,:)), test_cond(next:pts(i,:))];
filename = sprintf(‘%s_%d’,’test’,i);
save(filename, ‘matrix’)
next = pts(i);
end
if pts(i) == length(pts)
fin = 0;
end
return
end
NOW i want to write code to do whatever it is i want it to do and i want it to do it to each mat file.
i.e. go through each test and find all the zeroes, save those in a seperate file blah blah blah.
i know i have to use a loop but some advice as to the best and most efficent way to execute this would be great.
my coding is not fantastic so please, if you dont have anything useful or nice to contribute dont do it at all. thanks.Hello everyone. i am going to try give you as much information as possible. i know it may seem like a simple question but i am ripping my hair out.
ok so my original txt file has over 3000 rows of data and 5 columns.i have written a code that goes through the time (column 2) and identifies a change. That change in time corresponds to the start of a new test. For the original text file i found i have 3 tests, hence, 3 .mat files that i have saved using the following script. Each .mat file has 3 columns and multiple rows and each .mat file corresponds to a seperate test (like i mentioned). the columns are x,y, test condition 1 -18 etc.
pts = findchangepts(data(:,2), ‘Statistic’, ‘linear’, ‘MinThreshold’,100)
pts(end+1) = finalrow;
num_step = data(:,1)
x = data(:,4);
y = data(:,5);
fin = 1;
next = 1;
while(fin)
% make seperate files for the tests.
for i=1:length(pts)
matrix = [x(next:pts(i,:)), y(next:pts(i,:)), test_cond(next:pts(i,:))];
filename = sprintf(‘%s_%d’,’test’,i);
save(filename, ‘matrix’)
next = pts(i);
end
if pts(i) == length(pts)
fin = 0;
end
return
end
NOW i want to write code to do whatever it is i want it to do and i want it to do it to each mat file.
i.e. go through each test and find all the zeroes, save those in a seperate file blah blah blah.
i know i have to use a loop but some advice as to the best and most efficent way to execute this would be great.
my coding is not fantastic so please, if you dont have anything useful or nice to contribute dont do it at all. thanks. Hello everyone. i am going to try give you as much information as possible. i know it may seem like a simple question but i am ripping my hair out.
ok so my original txt file has over 3000 rows of data and 5 columns.i have written a code that goes through the time (column 2) and identifies a change. That change in time corresponds to the start of a new test. For the original text file i found i have 3 tests, hence, 3 .mat files that i have saved using the following script. Each .mat file has 3 columns and multiple rows and each .mat file corresponds to a seperate test (like i mentioned). the columns are x,y, test condition 1 -18 etc.
pts = findchangepts(data(:,2), ‘Statistic’, ‘linear’, ‘MinThreshold’,100)
pts(end+1) = finalrow;
num_step = data(:,1)
x = data(:,4);
y = data(:,5);
fin = 1;
next = 1;
while(fin)
% make seperate files for the tests.
for i=1:length(pts)
matrix = [x(next:pts(i,:)), y(next:pts(i,:)), test_cond(next:pts(i,:))];
filename = sprintf(‘%s_%d’,’test’,i);
save(filename, ‘matrix’)
next = pts(i);
end
if pts(i) == length(pts)
fin = 0;
end
return
end
NOW i want to write code to do whatever it is i want it to do and i want it to do it to each mat file.
i.e. go through each test and find all the zeroes, save those in a seperate file blah blah blah.
i know i have to use a loop but some advice as to the best and most efficent way to execute this would be great.
my coding is not fantastic so please, if you dont have anything useful or nice to contribute dont do it at all. thanks. loops, iterations, for loops, while loops, mat files, .mat, .txt, if statements, arrays, matrix, saving files, loading files MATLAB Answers — New Questions
How to integrate freeRTOS to C2000 blocksets?
I am using F2838x family microcontroller and i have to use FreeRTOS for scheduling purpose but there is no any option available to select, only Base Rate trigger option are available, Help me to, how i can integrate the FreeRTOS for that also i have checked that option available for STM32 family.I am using F2838x family microcontroller and i have to use FreeRTOS for scheduling purpose but there is no any option available to select, only Base Rate trigger option are available, Help me to, how i can integrate the FreeRTOS for that also i have checked that option available for STM32 family. I am using F2838x family microcontroller and i have to use FreeRTOS for scheduling purpose but there is no any option available to select, only Base Rate trigger option are available, Help me to, how i can integrate the FreeRTOS for that also i have checked that option available for STM32 family. c20000_freertos MATLAB Answers — New Questions
Edge lines not drawn when adjacent patch is transparent
Hi!
I have a problem when rendering large 3D patches of cubes. Some of my patches are transparent and some are not. The edges drawn between vertices shared by a transparent face and a opaque face is not always shown. I’ve attached a small example of code showing this behaviour below, which mimics my full plot function.
clear; clc
FirstElementAlpha = 0.;
SecondElementAlpha = 0.8;
verts = [
0 0 0;
0 1 0;
0 0 1;
0 1 1;
1 0 0;
1 1 0;
1 0 1;
1 1 1;
2 0 0;
2 1 0;
2 0 1;
2 1 1;
];
faces = [
1 2 4 3;
2 4 8 6;
1 3 7 5;
5 6 8 7;
1 2 6 5;
3 4 8 7;
5 6 8 7;
6 8 12 10;
5 7 11 9;
9 10 12 11;
5 6 10 9;
7 8 12 11;
];
facealp = [
FirstElementAlpha*ones(6,1);
SecondElementAlpha*ones(6,1);
];
colormap pink
p = patch(‘Faces’,faces,’Vertices’,verts,’Facecolor’,’flat’,’EdgeAlpha’,’flat’,’FaceAlpha’,’flat’, …
‘FaceVertexAlphaData’,facealp,’FaceVertexCData’,1-facealp,’Linewidth’,2);
p.Parent.CLim = [0 1];
view(3)
axis equal
However, if flipping the transparancy of the two elements, all edges are shown.
I want the edges to always be drawn around faces, and the transparancy of this edge to be defined by the facealpha value. Im guessing that patch defines lines between vertices, and i overwrite a opaque line with a transparant line in my code.
Is there a way to keep the line with the largest alpha value?
Can i modify my plot function, to achieve this in another way?Hi!
I have a problem when rendering large 3D patches of cubes. Some of my patches are transparent and some are not. The edges drawn between vertices shared by a transparent face and a opaque face is not always shown. I’ve attached a small example of code showing this behaviour below, which mimics my full plot function.
clear; clc
FirstElementAlpha = 0.;
SecondElementAlpha = 0.8;
verts = [
0 0 0;
0 1 0;
0 0 1;
0 1 1;
1 0 0;
1 1 0;
1 0 1;
1 1 1;
2 0 0;
2 1 0;
2 0 1;
2 1 1;
];
faces = [
1 2 4 3;
2 4 8 6;
1 3 7 5;
5 6 8 7;
1 2 6 5;
3 4 8 7;
5 6 8 7;
6 8 12 10;
5 7 11 9;
9 10 12 11;
5 6 10 9;
7 8 12 11;
];
facealp = [
FirstElementAlpha*ones(6,1);
SecondElementAlpha*ones(6,1);
];
colormap pink
p = patch(‘Faces’,faces,’Vertices’,verts,’Facecolor’,’flat’,’EdgeAlpha’,’flat’,’FaceAlpha’,’flat’, …
‘FaceVertexAlphaData’,facealp,’FaceVertexCData’,1-facealp,’Linewidth’,2);
p.Parent.CLim = [0 1];
view(3)
axis equal
However, if flipping the transparancy of the two elements, all edges are shown.
I want the edges to always be drawn around faces, and the transparancy of this edge to be defined by the facealpha value. Im guessing that patch defines lines between vertices, and i overwrite a opaque line with a transparant line in my code.
Is there a way to keep the line with the largest alpha value?
Can i modify my plot function, to achieve this in another way? Hi!
I have a problem when rendering large 3D patches of cubes. Some of my patches are transparent and some are not. The edges drawn between vertices shared by a transparent face and a opaque face is not always shown. I’ve attached a small example of code showing this behaviour below, which mimics my full plot function.
clear; clc
FirstElementAlpha = 0.;
SecondElementAlpha = 0.8;
verts = [
0 0 0;
0 1 0;
0 0 1;
0 1 1;
1 0 0;
1 1 0;
1 0 1;
1 1 1;
2 0 0;
2 1 0;
2 0 1;
2 1 1;
];
faces = [
1 2 4 3;
2 4 8 6;
1 3 7 5;
5 6 8 7;
1 2 6 5;
3 4 8 7;
5 6 8 7;
6 8 12 10;
5 7 11 9;
9 10 12 11;
5 6 10 9;
7 8 12 11;
];
facealp = [
FirstElementAlpha*ones(6,1);
SecondElementAlpha*ones(6,1);
];
colormap pink
p = patch(‘Faces’,faces,’Vertices’,verts,’Facecolor’,’flat’,’EdgeAlpha’,’flat’,’FaceAlpha’,’flat’, …
‘FaceVertexAlphaData’,facealp,’FaceVertexCData’,1-facealp,’Linewidth’,2);
p.Parent.CLim = [0 1];
view(3)
axis equal
However, if flipping the transparancy of the two elements, all edges are shown.
I want the edges to always be drawn around faces, and the transparancy of this edge to be defined by the facealpha value. Im guessing that patch defines lines between vertices, and i overwrite a opaque line with a transparant line in my code.
Is there a way to keep the line with the largest alpha value?
Can i modify my plot function, to achieve this in another way? patch, alpha, edges, plotting MATLAB Answers — New Questions
iterative estimation of eigenvalues and eigenvectors by the inverse power method. Your MATLAB/Octave code shouldn’t be hardcoded. ● Calculate the eigenvectors and eigenvalues
function [lambda, v] = inverse_power_method(A, tol, max_iter)
% This function uses the inverse power method to estimate the smallest
% eigenvalue and corresponding eigenvector of matrix A.
% Inputs:
% A – The input square matrix
% tol – The tolerance for convergence (e.g., 1e-6)
% max_iter – The maximum number of iterations
% Outputs:
% lambda – The estimated smallest eigenvalue
% v – The estimated corresponding eigenvector
n = size(A, 1); % Get the size of the matrix
v = rand(n, 1); % Initialize a random vector
v = v / norm(v); % Normalize the vector
% Perform the inverse power iteration
for k = 1:max_iter
w = (A v); % Solve A * w = v
v_new = w / norm(w); % Normalize the vector
% Check for convergence
if norm(v_new – v) < tol
break;
end
v = v_new; % Update the vector
end
% Calculate the corresponding eigenvalue
lambda = v’ * A * v;
% Normalize the eigenvector to have unit length
v = v / norm(v);
end
% Define the matrix A
A = [1, -3, 3;
3, -5, 3;
6, -6, 4];
% Set the tolerance and maximum number of iterations
tol = 1e-6;
max_iter = 1000;
% Call the inverse power method function
[lambda, v] = inverse_power_method(A, tol, max_iter);
% Display the results
fprintf(‘Estimated smallest eigenvalue: %.6fn’, lambda);
fprintf(‘Estimated corresponding eigenvector:n’);
disp(v);function [lambda, v] = inverse_power_method(A, tol, max_iter)
% This function uses the inverse power method to estimate the smallest
% eigenvalue and corresponding eigenvector of matrix A.
% Inputs:
% A – The input square matrix
% tol – The tolerance for convergence (e.g., 1e-6)
% max_iter – The maximum number of iterations
% Outputs:
% lambda – The estimated smallest eigenvalue
% v – The estimated corresponding eigenvector
n = size(A, 1); % Get the size of the matrix
v = rand(n, 1); % Initialize a random vector
v = v / norm(v); % Normalize the vector
% Perform the inverse power iteration
for k = 1:max_iter
w = (A v); % Solve A * w = v
v_new = w / norm(w); % Normalize the vector
% Check for convergence
if norm(v_new – v) < tol
break;
end
v = v_new; % Update the vector
end
% Calculate the corresponding eigenvalue
lambda = v’ * A * v;
% Normalize the eigenvector to have unit length
v = v / norm(v);
end
% Define the matrix A
A = [1, -3, 3;
3, -5, 3;
6, -6, 4];
% Set the tolerance and maximum number of iterations
tol = 1e-6;
max_iter = 1000;
% Call the inverse power method function
[lambda, v] = inverse_power_method(A, tol, max_iter);
% Display the results
fprintf(‘Estimated smallest eigenvalue: %.6fn’, lambda);
fprintf(‘Estimated corresponding eigenvector:n’);
disp(v); function [lambda, v] = inverse_power_method(A, tol, max_iter)
% This function uses the inverse power method to estimate the smallest
% eigenvalue and corresponding eigenvector of matrix A.
% Inputs:
% A – The input square matrix
% tol – The tolerance for convergence (e.g., 1e-6)
% max_iter – The maximum number of iterations
% Outputs:
% lambda – The estimated smallest eigenvalue
% v – The estimated corresponding eigenvector
n = size(A, 1); % Get the size of the matrix
v = rand(n, 1); % Initialize a random vector
v = v / norm(v); % Normalize the vector
% Perform the inverse power iteration
for k = 1:max_iter
w = (A v); % Solve A * w = v
v_new = w / norm(w); % Normalize the vector
% Check for convergence
if norm(v_new – v) < tol
break;
end
v = v_new; % Update the vector
end
% Calculate the corresponding eigenvalue
lambda = v’ * A * v;
% Normalize the eigenvector to have unit length
v = v / norm(v);
end
% Define the matrix A
A = [1, -3, 3;
3, -5, 3;
6, -6, 4];
% Set the tolerance and maximum number of iterations
tol = 1e-6;
max_iter = 1000;
% Call the inverse power method function
[lambda, v] = inverse_power_method(A, tol, max_iter);
% Display the results
fprintf(‘Estimated smallest eigenvalue: %.6fn’, lambda);
fprintf(‘Estimated corresponding eigenvector:n’);
disp(v); can you please see this accurate this to get answe MATLAB Answers — New Questions
How can I solve an equation using fixed point method?
g(x)=2^-x;
[1/3,1];
tol=10^-4;
max=100g(x)=2^-x;
[1/3,1];
tol=10^-4;
max=100 g(x)=2^-x;
[1/3,1];
tol=10^-4;
max=100 numerical analysis MATLAB Answers — New Questions