Tag Archives: matlab
Client installation package for Mathlab
Hi all,
I’m looking for a way to create a "universal" installation package for Matlab.
Our users will not have local admin and due to security policies the software is installed by packages.
However im under the impression that there is no generic software install and that all specific features require a specific installation procedure.
Can you tell me if there is a way to achieve this? Or is it an option to use the webbased version somehow?
Any help is welcome.
Regards,Hi all,
I’m looking for a way to create a "universal" installation package for Matlab.
Our users will not have local admin and due to security policies the software is installed by packages.
However im under the impression that there is no generic software install and that all specific features require a specific installation procedure.
Can you tell me if there is a way to achieve this? Or is it an option to use the webbased version somehow?
Any help is welcome.
Regards, Hi all,
I’m looking for a way to create a "universal" installation package for Matlab.
Our users will not have local admin and due to security policies the software is installed by packages.
However im under the impression that there is no generic software install and that all specific features require a specific installation procedure.
Can you tell me if there is a way to achieve this? Or is it an option to use the webbased version somehow?
Any help is welcome.
Regards, mathlab installation package MATLAB Answers — New Questions
How do I add shapes to my Simulink model
I want to add a dotted line to add clarity to my model. In addition, I want to add a box to show future addition.
I do I add static shapes and figures (rectangle) to my model?I want to add a dotted line to add clarity to my model. In addition, I want to add a box to show future addition.
I do I add static shapes and figures (rectangle) to my model? I want to add a dotted line to add clarity to my model. In addition, I want to add a box to show future addition.
I do I add static shapes and figures (rectangle) to my model? static shapes MATLAB Answers — New Questions
Complex matlab script migration into simulink
I’m currently working with a rather length Matlab script, and am trying to move it onto simulink to adopt a more ‘drag n drop’ logic flow, as in Simulink we are able to use both custom function blocks as well as default lib blocks. After trying to move this script to Simulink I realized that I have been running into a lot of code generation incompatibility errors, I’d like to ask whether I can "pull" a plot from the base Matlab workspace into Simulink when I run a Simulink function?
Say that I click on a specific block on Simulink that triggers a script in the base workspace to run, and then the results and plots from the base workspace script are "sent" to Simulink.
Is this achievable?
Thanks!I’m currently working with a rather length Matlab script, and am trying to move it onto simulink to adopt a more ‘drag n drop’ logic flow, as in Simulink we are able to use both custom function blocks as well as default lib blocks. After trying to move this script to Simulink I realized that I have been running into a lot of code generation incompatibility errors, I’d like to ask whether I can "pull" a plot from the base Matlab workspace into Simulink when I run a Simulink function?
Say that I click on a specific block on Simulink that triggers a script in the base workspace to run, and then the results and plots from the base workspace script are "sent" to Simulink.
Is this achievable?
Thanks! I’m currently working with a rather length Matlab script, and am trying to move it onto simulink to adopt a more ‘drag n drop’ logic flow, as in Simulink we are able to use both custom function blocks as well as default lib blocks. After trying to move this script to Simulink I realized that I have been running into a lot of code generation incompatibility errors, I’d like to ask whether I can "pull" a plot from the base Matlab workspace into Simulink when I run a Simulink function?
Say that I click on a specific block on Simulink that triggers a script in the base workspace to run, and then the results and plots from the base workspace script are "sent" to Simulink.
Is this achievable?
Thanks! simulink, matlab code, code generation MATLAB Answers — New Questions
Keyboard remapping in live editor not working.
Hi guys,
I’m on a mac here and have remapped the begin and end keys to "begin line" and "end line" in matlab.
I have also removed these keys from "begin doc" and "end doc".
This works perfectly in the main editor and command windows but is totally ignored in the live editor where the original "begin doc" and "end doc" are still mapped to the keys.
Am I doing something wrong or is this a bug?
Thanks for any help
AndyHi guys,
I’m on a mac here and have remapped the begin and end keys to "begin line" and "end line" in matlab.
I have also removed these keys from "begin doc" and "end doc".
This works perfectly in the main editor and command windows but is totally ignored in the live editor where the original "begin doc" and "end doc" are still mapped to the keys.
Am I doing something wrong or is this a bug?
Thanks for any help
Andy Hi guys,
I’m on a mac here and have remapped the begin and end keys to "begin line" and "end line" in matlab.
I have also removed these keys from "begin doc" and "end doc".
This works perfectly in the main editor and command windows but is totally ignored in the live editor where the original "begin doc" and "end doc" are still mapped to the keys.
Am I doing something wrong or is this a bug?
Thanks for any help
Andy live editor, keyboard remapping MATLAB Answers — New Questions
optimization expression includes an integration
I am trying an optimization problem in which the expression of the objective function includes an integral.
It is obvious that the sigma equal to one results in the optimium solution. I want to use the optimization toolbox to get this result with an initial sigma equal to, say, 10.
I wrote the following code.
g1 = @(x,c) (exp(-(0.5*(x./c).^2))./sqrt(2*pi*c^2));
c = optimvar("c",1,1,’Type’,’continuous’,’LowerBound’,0.1,’UpperBound’,10);
prob = optimproblem(‘Objective’, (0.5 – integral(@(x)g1(x,c),0, 10)).^2);
[solf,fvalf,eflagf,outputf] = solve(prob)
The following error is generated.
Error using integralCalc>finalInputChecks (line 544)
Input function must return ‘double’ or ‘single’ values. Found
‘optim.problemdef.OptimizationExpression’.
I have two questions:
1, Am I coding the problem properly/correctly?
2, If the code is basically correct, how can I solve the error?
Thank you.I am trying an optimization problem in which the expression of the objective function includes an integral.
It is obvious that the sigma equal to one results in the optimium solution. I want to use the optimization toolbox to get this result with an initial sigma equal to, say, 10.
I wrote the following code.
g1 = @(x,c) (exp(-(0.5*(x./c).^2))./sqrt(2*pi*c^2));
c = optimvar("c",1,1,’Type’,’continuous’,’LowerBound’,0.1,’UpperBound’,10);
prob = optimproblem(‘Objective’, (0.5 – integral(@(x)g1(x,c),0, 10)).^2);
[solf,fvalf,eflagf,outputf] = solve(prob)
The following error is generated.
Error using integralCalc>finalInputChecks (line 544)
Input function must return ‘double’ or ‘single’ values. Found
‘optim.problemdef.OptimizationExpression’.
I have two questions:
1, Am I coding the problem properly/correctly?
2, If the code is basically correct, how can I solve the error?
Thank you. I am trying an optimization problem in which the expression of the objective function includes an integral.
It is obvious that the sigma equal to one results in the optimium solution. I want to use the optimization toolbox to get this result with an initial sigma equal to, say, 10.
I wrote the following code.
g1 = @(x,c) (exp(-(0.5*(x./c).^2))./sqrt(2*pi*c^2));
c = optimvar("c",1,1,’Type’,’continuous’,’LowerBound’,0.1,’UpperBound’,10);
prob = optimproblem(‘Objective’, (0.5 – integral(@(x)g1(x,c),0, 10)).^2);
[solf,fvalf,eflagf,outputf] = solve(prob)
The following error is generated.
Error using integralCalc>finalInputChecks (line 544)
Input function must return ‘double’ or ‘single’ values. Found
‘optim.problemdef.OptimizationExpression’.
I have two questions:
1, Am I coding the problem properly/correctly?
2, If the code is basically correct, how can I solve the error?
Thank you. #optimization #integral MATLAB Answers — New Questions
How to Graph integrals?
Hello everybody,
I have a little trouble here. I’m trying to graph the following auction at first price:
syms x a
gamma = 0.3;
b_hat= 0.542;
fun = b/2;
F(a) = int(fun, x, 0, a);
fplot(F,[0 1])
But I still can’t get it, I would appreciate it if you could help me.Hello everybody,
I have a little trouble here. I’m trying to graph the following auction at first price:
syms x a
gamma = 0.3;
b_hat= 0.542;
fun = b/2;
F(a) = int(fun, x, 0, a);
fplot(F,[0 1])
But I still can’t get it, I would appreciate it if you could help me. Hello everybody,
I have a little trouble here. I’m trying to graph the following auction at first price:
syms x a
gamma = 0.3;
b_hat= 0.542;
fun = b/2;
F(a) = int(fun, x, 0, a);
fplot(F,[0 1])
But I still can’t get it, I would appreciate it if you could help me. graph, integrals MATLAB Answers — New Questions
Connecting Xbox Controller to Simulink Real-Time
Hi,
Im trying to add a xbox controller to my simulink Real-Time. However the only blocks I could find and use only work for normal simulink. I tried using Gamepad Simulator block and the Joystick Input block and I tested and worked only for normal Simulink. When I try to use them in Simulink Real-Time, it doesnt take the values. When I use the the JoyStick input block in simulink real-time, it gives me an error and says "Error:Unable to find S-function module ‘joyinput’. S-function modules must exist as either source files or pre-compiled object files on the MATLAB path.".
Is there a way to get around this?
ThanksHi,
Im trying to add a xbox controller to my simulink Real-Time. However the only blocks I could find and use only work for normal simulink. I tried using Gamepad Simulator block and the Joystick Input block and I tested and worked only for normal Simulink. When I try to use them in Simulink Real-Time, it doesnt take the values. When I use the the JoyStick input block in simulink real-time, it gives me an error and says "Error:Unable to find S-function module ‘joyinput’. S-function modules must exist as either source files or pre-compiled object files on the MATLAB path.".
Is there a way to get around this?
Thanks Hi,
Im trying to add a xbox controller to my simulink Real-Time. However the only blocks I could find and use only work for normal simulink. I tried using Gamepad Simulator block and the Joystick Input block and I tested and worked only for normal Simulink. When I try to use them in Simulink Real-Time, it doesnt take the values. When I use the the JoyStick input block in simulink real-time, it gives me an error and says "Error:Unable to find S-function module ‘joyinput’. S-function modules must exist as either source files or pre-compiled object files on the MATLAB path.".
Is there a way to get around this?
Thanks simulink, simulink realtime MATLAB Answers — New Questions
contour plot problem Z must be at least a 2×2 matrix
Hallo everyone,
i have a problem to make the contour plot, it always shows Z must be at least a 2×2 matrix. i have try my best to solve, but it still not work, could you please to help me? The code is as follows.
x=[80;100;90;90;90]
y=[4;4;2;6;4]
[X,Y] = meshgrid(x,y)
% Polly 11 f(x,y)=p00+p10*x+p01*y
f1=1.7419-0.0006*x+0.0132*y
contour(X,Y,f1)
Thanks and best regards
JLHallo everyone,
i have a problem to make the contour plot, it always shows Z must be at least a 2×2 matrix. i have try my best to solve, but it still not work, could you please to help me? The code is as follows.
x=[80;100;90;90;90]
y=[4;4;2;6;4]
[X,Y] = meshgrid(x,y)
% Polly 11 f(x,y)=p00+p10*x+p01*y
f1=1.7419-0.0006*x+0.0132*y
contour(X,Y,f1)
Thanks and best regards
JL Hallo everyone,
i have a problem to make the contour plot, it always shows Z must be at least a 2×2 matrix. i have try my best to solve, but it still not work, could you please to help me? The code is as follows.
x=[80;100;90;90;90]
y=[4;4;2;6;4]
[X,Y] = meshgrid(x,y)
% Polly 11 f(x,y)=p00+p10*x+p01*y
f1=1.7419-0.0006*x+0.0132*y
contour(X,Y,f1)
Thanks and best regards
JL contour MATLAB Answers — New Questions
Simulink bandpass filter live signaling
Hello everyone,
I am currently working in Matlab’s simulink to filter live SEMG signaling. I have created an application pathway, with a RMS filter, and normilization, right now I am not fully understanding how to create a Bandpass filter. I have a buffer of 5 and I am trying to have an ouput of 1.
Could anyone explain the dimesions I should implement in the Frequency specifications. Thank you in advancedHello everyone,
I am currently working in Matlab’s simulink to filter live SEMG signaling. I have created an application pathway, with a RMS filter, and normilization, right now I am not fully understanding how to create a Bandpass filter. I have a buffer of 5 and I am trying to have an ouput of 1.
Could anyone explain the dimesions I should implement in the Frequency specifications. Thank you in advanced Hello everyone,
I am currently working in Matlab’s simulink to filter live SEMG signaling. I have created an application pathway, with a RMS filter, and normilization, right now I am not fully understanding how to create a Bandpass filter. I have a buffer of 5 and I am trying to have an ouput of 1.
Could anyone explain the dimesions I should implement in the Frequency specifications. Thank you in advanced simulink, bandpassfilter MATLAB Answers — New Questions
How to import KNN-model structure from matlab into simulink
All,
The problem I am facing is a move of KNN-model data structure from matlab to simulink in a loop:
In matlab TrainingData is used as input to create an KNN based-model. In simulink, at some point, I want to use this model to predict the outcome of a certain decision based on certain parameters that evolve during simulation. If the simulation ends, the outcome of the decsion is used in matlab to adjust the TrainingData and to update the KNN-model. The updated KNN-model will be used for the next simutlation.
Note that before the loop starts, the feature table exists.
Note that in matlab, the knn-model data is the outcome of the command: knnmodel = fitcknn(TrainingData, ‘feature’). So i need to import this knnmodel structure into simulink.
My problem is that I do not see how to successfully import such KNN-model into the simulink model for decision making (prediction).
Is there any method to get this done?All,
The problem I am facing is a move of KNN-model data structure from matlab to simulink in a loop:
In matlab TrainingData is used as input to create an KNN based-model. In simulink, at some point, I want to use this model to predict the outcome of a certain decision based on certain parameters that evolve during simulation. If the simulation ends, the outcome of the decsion is used in matlab to adjust the TrainingData and to update the KNN-model. The updated KNN-model will be used for the next simutlation.
Note that before the loop starts, the feature table exists.
Note that in matlab, the knn-model data is the outcome of the command: knnmodel = fitcknn(TrainingData, ‘feature’). So i need to import this knnmodel structure into simulink.
My problem is that I do not see how to successfully import such KNN-model into the simulink model for decision making (prediction).
Is there any method to get this done? All,
The problem I am facing is a move of KNN-model data structure from matlab to simulink in a loop:
In matlab TrainingData is used as input to create an KNN based-model. In simulink, at some point, I want to use this model to predict the outcome of a certain decision based on certain parameters that evolve during simulation. If the simulation ends, the outcome of the decsion is used in matlab to adjust the TrainingData and to update the KNN-model. The updated KNN-model will be used for the next simutlation.
Note that before the loop starts, the feature table exists.
Note that in matlab, the knn-model data is the outcome of the command: knnmodel = fitcknn(TrainingData, ‘feature’). So i need to import this knnmodel structure into simulink.
My problem is that I do not see how to successfully import such KNN-model into the simulink model for decision making (prediction).
Is there any method to get this done? machine learning, matlab, simulink MATLAB Answers — New Questions
Can I download previous releases of MATLAB?
Can I download previous releases of MATLAB?Can I download previous releases of MATLAB? Can I download previous releases of MATLAB? MATLAB Answers — New Questions
Formatting input data for linear regression model in leave-out-one validation testing
Hello there I have data from 10 trials stored in a 10×1 cell (Predictors) and the corespoding respose vairables stored in a 10×1 cell (Response). I am trying to trian a simple linear regression model and make predictions by leaving one trial out and using the other 9 trials to train the linear regression model and the one to predict/test the model by producing RMSE values. I am unsure of how to format my input within the "fitlm" function as I keep getting the follwing error:
% Train the network
for i = 1:length(Predictors) %iterate over all data points
validationdataX = Predictors(i);
validationdataY = Response(i);
%Exclude the current index (i) for training
trainingIndices = setdiff(1:length(Predictors),i);
traningdataX = Predictors(trainingIndices)
trainingdataY = Response(trainingIndices)
net = fitlm(traningdataX,trainingdataY)
ypred = predict(net,validationdataX);
TrueVal = validationdataY;
TrueValue = cell2mat(TrueVal);
Predvalue = {Predval};
PredictedValue = cell2mat(Predvalue);
RMSE = rmse(PredictedValue,TrueValue)
end
Error using classreg.regr.TermsRegression/handleDataArgs (line 589)
Predictor variables must be numeric vectors, numeric matrices, or categorical vectors.
Error in LinearModel.fit (line 1000)
[X,y,haveDataset,otherArgs] = LinearModel.handleDataArgs(X,paramNames,varargin{:});
Error in fitlm (line 134)
model = LinearModel.fit(X,varargin{:});
Any suggestions on how to fix this and to get the model to work correcly and make predictions using leave out one validation approach would be greatly appreciated!Hello there I have data from 10 trials stored in a 10×1 cell (Predictors) and the corespoding respose vairables stored in a 10×1 cell (Response). I am trying to trian a simple linear regression model and make predictions by leaving one trial out and using the other 9 trials to train the linear regression model and the one to predict/test the model by producing RMSE values. I am unsure of how to format my input within the "fitlm" function as I keep getting the follwing error:
% Train the network
for i = 1:length(Predictors) %iterate over all data points
validationdataX = Predictors(i);
validationdataY = Response(i);
%Exclude the current index (i) for training
trainingIndices = setdiff(1:length(Predictors),i);
traningdataX = Predictors(trainingIndices)
trainingdataY = Response(trainingIndices)
net = fitlm(traningdataX,trainingdataY)
ypred = predict(net,validationdataX);
TrueVal = validationdataY;
TrueValue = cell2mat(TrueVal);
Predvalue = {Predval};
PredictedValue = cell2mat(Predvalue);
RMSE = rmse(PredictedValue,TrueValue)
end
Error using classreg.regr.TermsRegression/handleDataArgs (line 589)
Predictor variables must be numeric vectors, numeric matrices, or categorical vectors.
Error in LinearModel.fit (line 1000)
[X,y,haveDataset,otherArgs] = LinearModel.handleDataArgs(X,paramNames,varargin{:});
Error in fitlm (line 134)
model = LinearModel.fit(X,varargin{:});
Any suggestions on how to fix this and to get the model to work correcly and make predictions using leave out one validation approach would be greatly appreciated! Hello there I have data from 10 trials stored in a 10×1 cell (Predictors) and the corespoding respose vairables stored in a 10×1 cell (Response). I am trying to trian a simple linear regression model and make predictions by leaving one trial out and using the other 9 trials to train the linear regression model and the one to predict/test the model by producing RMSE values. I am unsure of how to format my input within the "fitlm" function as I keep getting the follwing error:
% Train the network
for i = 1:length(Predictors) %iterate over all data points
validationdataX = Predictors(i);
validationdataY = Response(i);
%Exclude the current index (i) for training
trainingIndices = setdiff(1:length(Predictors),i);
traningdataX = Predictors(trainingIndices)
trainingdataY = Response(trainingIndices)
net = fitlm(traningdataX,trainingdataY)
ypred = predict(net,validationdataX);
TrueVal = validationdataY;
TrueValue = cell2mat(TrueVal);
Predvalue = {Predval};
PredictedValue = cell2mat(Predvalue);
RMSE = rmse(PredictedValue,TrueValue)
end
Error using classreg.regr.TermsRegression/handleDataArgs (line 589)
Predictor variables must be numeric vectors, numeric matrices, or categorical vectors.
Error in LinearModel.fit (line 1000)
[X,y,haveDataset,otherArgs] = LinearModel.handleDataArgs(X,paramNames,varargin{:});
Error in fitlm (line 134)
model = LinearModel.fit(X,varargin{:});
Any suggestions on how to fix this and to get the model to work correcly and make predictions using leave out one validation approach would be greatly appreciated! linear regression, input data formatting, validation MATLAB Answers — New Questions
How can I clear an error “The expression to the left of the equals sign is not a valid target for an assignment?”
I tried to solve a problem (see the attachments). But I gor an error "The expression to the left of the equals sign is not a valid target for an assignment". How to solve this issue.I tried to solve a problem (see the attachments). But I gor an error "The expression to the left of the equals sign is not a valid target for an assignment". How to solve this issue. I tried to solve a problem (see the attachments). But I gor an error "The expression to the left of the equals sign is not a valid target for an assignment". How to solve this issue. bvp4c MATLAB Answers — New Questions
How can i fit the inscribed circle with different diameter in an image ??
I have an image which has the close shape. I need to fill the the close loop with different diameter in the image. Can anyone give the suggestion for that ??I have an image which has the close shape. I need to fill the the close loop with different diameter in the image. Can anyone give the suggestion for that ?? I have an image which has the close shape. I need to fill the the close loop with different diameter in the image. Can anyone give the suggestion for that ?? fill, prescribed circle, image processing MATLAB Answers — New Questions
Adding standard deviation as a bar to a scatter plot
Hello all, I’m plotting weather data and want to show the mean, standard deviation and min-max values in one plot. I’ve attached a photo of the ideal end result. How might I go about it using the data below as an example?
Mean_Temp_1 = [12]
Mean_Temp_2 = [15]
Mean_Temp_3 = [11]
SD_1 = [1.2]
SD_2 = [0.8]
SD_3 = [1.4]
Max_1 = [14]
Max_2 = [17]
Max_3 = [12]
Min_1 = [10]
Min_2 = [12]
Min_3 = [10]Hello all, I’m plotting weather data and want to show the mean, standard deviation and min-max values in one plot. I’ve attached a photo of the ideal end result. How might I go about it using the data below as an example?
Mean_Temp_1 = [12]
Mean_Temp_2 = [15]
Mean_Temp_3 = [11]
SD_1 = [1.2]
SD_2 = [0.8]
SD_3 = [1.4]
Max_1 = [14]
Max_2 = [17]
Max_3 = [12]
Min_1 = [10]
Min_2 = [12]
Min_3 = [10] Hello all, I’m plotting weather data and want to show the mean, standard deviation and min-max values in one plot. I’ve attached a photo of the ideal end result. How might I go about it using the data below as an example?
Mean_Temp_1 = [12]
Mean_Temp_2 = [15]
Mean_Temp_3 = [11]
SD_1 = [1.2]
SD_2 = [0.8]
SD_3 = [1.4]
Max_1 = [14]
Max_2 = [17]
Max_3 = [12]
Min_1 = [10]
Min_2 = [12]
Min_3 = [10] scatter MATLAB Answers — New Questions
Curve Fitting complex data (x,y) for constant extraction.
Hello,
I’ve been following the following link — https://www.mathworks.com/help/optim/ug/fit-model-to-complex-data.html#
to try and extract the real constants (N_s,Tau_s, and c) from the Drude-Smith derivation for complex conductivity. This involves fitting both the real and imaginary components (which may be the problem in itself, since the example fits regular data with complex noise?)
I’ve attempted both lsqnonlin and lsqcurve fit methods.
file =[‘DSfit_Sitest.xls’]; %%file attached
input = xlsread(file);
x = input(:,1); %%%% xdata, freqency, omega, real numbers from (0.2-1.4 THz)
R = input(:,2); %%%% Real component (blue in plot)
I = input(:,3);%%%% Imaginary component (orange in plot)
ydata = complex(R,I); %%%% complex conductivity, sigma_s
q = 1.602E-19; %% charge
m = 0.98; %% effective electron mass
mi = 1/0.98; %% inverse electron mass used to make typing the equation simpler
objfcn = @(C)(((C(1)*(q^2)*mi*C(2))./(1-1i.*x.*C(2))).*(1+(C(3)./(1-1i.*x.*C(2))))) – ydata;
opts = optimoptions(@lsqnonlin,’Display’,’off’);
x0=[1e17, 100, -0.1]; %% initial guesses, I expect these to be reasonable values
LB = [1e15, 1, -1]; %%Typical carrier concentrations (cm-3), Tau_s (C(2)) units in picoseconds, -1<c<0
UB = [1e21, 1000, 0];
[const,~,residual,exitflag,output] = lsqnonlin(objfcn,x0,[],[],opts); %% does not run with LB and UB, so i leave blank.
This method outputs the initial guesses, and when I use the initial guesses to plot the outputs I get my data graph flipped, meaning my function just equals zero.
Using lsqcurvefit
objfcn = @(C,x)(((C(1)*(q^2).*mi.*C(2))./(1-1i.*x.*C(2))).*(1+(C(3)./(1-1i.*x.*C(2)))));
opts = optimoptions(@lsqcurvefit,opts);
x0=[1e17, 100, -0.1];
LB = [1e15, 1, -1];
UB = [1e21, 1e3, 0];
[constan,resnorm] = lsqcurvefit(objfcn,x0,x,ydata,[],[],opts)
I get the error "not enough input arguments" in my objfcn, and it still outputs the initial guesses
Any help with why this isnt working or if im doing something really wrong is greatly appreciated! I am a novice Matlab user.
Thank you!!Hello,
I’ve been following the following link — https://www.mathworks.com/help/optim/ug/fit-model-to-complex-data.html#
to try and extract the real constants (N_s,Tau_s, and c) from the Drude-Smith derivation for complex conductivity. This involves fitting both the real and imaginary components (which may be the problem in itself, since the example fits regular data with complex noise?)
I’ve attempted both lsqnonlin and lsqcurve fit methods.
file =[‘DSfit_Sitest.xls’]; %%file attached
input = xlsread(file);
x = input(:,1); %%%% xdata, freqency, omega, real numbers from (0.2-1.4 THz)
R = input(:,2); %%%% Real component (blue in plot)
I = input(:,3);%%%% Imaginary component (orange in plot)
ydata = complex(R,I); %%%% complex conductivity, sigma_s
q = 1.602E-19; %% charge
m = 0.98; %% effective electron mass
mi = 1/0.98; %% inverse electron mass used to make typing the equation simpler
objfcn = @(C)(((C(1)*(q^2)*mi*C(2))./(1-1i.*x.*C(2))).*(1+(C(3)./(1-1i.*x.*C(2))))) – ydata;
opts = optimoptions(@lsqnonlin,’Display’,’off’);
x0=[1e17, 100, -0.1]; %% initial guesses, I expect these to be reasonable values
LB = [1e15, 1, -1]; %%Typical carrier concentrations (cm-3), Tau_s (C(2)) units in picoseconds, -1<c<0
UB = [1e21, 1000, 0];
[const,~,residual,exitflag,output] = lsqnonlin(objfcn,x0,[],[],opts); %% does not run with LB and UB, so i leave blank.
This method outputs the initial guesses, and when I use the initial guesses to plot the outputs I get my data graph flipped, meaning my function just equals zero.
Using lsqcurvefit
objfcn = @(C,x)(((C(1)*(q^2).*mi.*C(2))./(1-1i.*x.*C(2))).*(1+(C(3)./(1-1i.*x.*C(2)))));
opts = optimoptions(@lsqcurvefit,opts);
x0=[1e17, 100, -0.1];
LB = [1e15, 1, -1];
UB = [1e21, 1e3, 0];
[constan,resnorm] = lsqcurvefit(objfcn,x0,x,ydata,[],[],opts)
I get the error "not enough input arguments" in my objfcn, and it still outputs the initial guesses
Any help with why this isnt working or if im doing something really wrong is greatly appreciated! I am a novice Matlab user.
Thank you!! Hello,
I’ve been following the following link — https://www.mathworks.com/help/optim/ug/fit-model-to-complex-data.html#
to try and extract the real constants (N_s,Tau_s, and c) from the Drude-Smith derivation for complex conductivity. This involves fitting both the real and imaginary components (which may be the problem in itself, since the example fits regular data with complex noise?)
I’ve attempted both lsqnonlin and lsqcurve fit methods.
file =[‘DSfit_Sitest.xls’]; %%file attached
input = xlsread(file);
x = input(:,1); %%%% xdata, freqency, omega, real numbers from (0.2-1.4 THz)
R = input(:,2); %%%% Real component (blue in plot)
I = input(:,3);%%%% Imaginary component (orange in plot)
ydata = complex(R,I); %%%% complex conductivity, sigma_s
q = 1.602E-19; %% charge
m = 0.98; %% effective electron mass
mi = 1/0.98; %% inverse electron mass used to make typing the equation simpler
objfcn = @(C)(((C(1)*(q^2)*mi*C(2))./(1-1i.*x.*C(2))).*(1+(C(3)./(1-1i.*x.*C(2))))) – ydata;
opts = optimoptions(@lsqnonlin,’Display’,’off’);
x0=[1e17, 100, -0.1]; %% initial guesses, I expect these to be reasonable values
LB = [1e15, 1, -1]; %%Typical carrier concentrations (cm-3), Tau_s (C(2)) units in picoseconds, -1<c<0
UB = [1e21, 1000, 0];
[const,~,residual,exitflag,output] = lsqnonlin(objfcn,x0,[],[],opts); %% does not run with LB and UB, so i leave blank.
This method outputs the initial guesses, and when I use the initial guesses to plot the outputs I get my data graph flipped, meaning my function just equals zero.
Using lsqcurvefit
objfcn = @(C,x)(((C(1)*(q^2).*mi.*C(2))./(1-1i.*x.*C(2))).*(1+(C(3)./(1-1i.*x.*C(2)))));
opts = optimoptions(@lsqcurvefit,opts);
x0=[1e17, 100, -0.1];
LB = [1e15, 1, -1];
UB = [1e21, 1e3, 0];
[constan,resnorm] = lsqcurvefit(objfcn,x0,x,ydata,[],[],opts)
I get the error "not enough input arguments" in my objfcn, and it still outputs the initial guesses
Any help with why this isnt working or if im doing something really wrong is greatly appreciated! I am a novice Matlab user.
Thank you!! complex curve fitting, curvefitting, lsqcurvefit, lsqnonlin, complex data, drude-smith MATLAB Answers — New Questions
Is it possible to ADD a warning before Matlab starts?
So, I have the previously-reported issue that, on startup in Windows 10, Matlab reports that any folders that are on mapped network drives (Z:, Y: etc.) are "nonexistent or not a directory". I also lose any scripts or functions from those mapped folders that were open in the editor when Matlab was last shut down, so I have to find and re-open them.
The hack to get around this is to access the network drive(s) in Microsoft Windows Explorer/File Explorer, after which Matlab can see the folders in those drives – e.g. if functions or scripts were loaded into the editor, these will appear following the above hack.
What I’d like is a warning, before Matlab goes off and fails to find those mapped network drives, reminding me to open the offending drives in Windows Explorer before continuing.
Is there any way to do this via startup.m – or would it need a Windows batch file to incorporate the warning and the pause?So, I have the previously-reported issue that, on startup in Windows 10, Matlab reports that any folders that are on mapped network drives (Z:, Y: etc.) are "nonexistent or not a directory". I also lose any scripts or functions from those mapped folders that were open in the editor when Matlab was last shut down, so I have to find and re-open them.
The hack to get around this is to access the network drive(s) in Microsoft Windows Explorer/File Explorer, after which Matlab can see the folders in those drives – e.g. if functions or scripts were loaded into the editor, these will appear following the above hack.
What I’d like is a warning, before Matlab goes off and fails to find those mapped network drives, reminding me to open the offending drives in Windows Explorer before continuing.
Is there any way to do this via startup.m – or would it need a Windows batch file to incorporate the warning and the pause? So, I have the previously-reported issue that, on startup in Windows 10, Matlab reports that any folders that are on mapped network drives (Z:, Y: etc.) are "nonexistent or not a directory". I also lose any scripts or functions from those mapped folders that were open in the editor when Matlab was last shut down, so I have to find and re-open them.
The hack to get around this is to access the network drive(s) in Microsoft Windows Explorer/File Explorer, after which Matlab can see the folders in those drives – e.g. if functions or scripts were loaded into the editor, these will appear following the above hack.
What I’d like is a warning, before Matlab goes off and fails to find those mapped network drives, reminding me to open the offending drives in Windows Explorer before continuing.
Is there any way to do this via startup.m – or would it need a Windows batch file to incorporate the warning and the pause? startup, network issues, windows MATLAB Answers — New Questions
Find the intersection points between two data sets
If I have two data sets(each from xy data) and they are intersect at more than two points, How can I find the area between intersection points? If there are more than one area, i.e., Area1, Area2, etc, I would like to find each area separately and assign +ve and -ve sign to the areas? Figure and Example of my data is below (data1 and data2):
data1 = [575721.678739338 3189196.15577354
575711.702452018 3189195.13447944
575701.688569224 3189195.60208872
575691.697320475 3189195.17336187
575681.678990798 3189195.81713592
575676.797287407 3189195.96672958
575671.667154953 3189196.20376653
575661.619557374 3189198.00667871
575651.499830521 3189202.66611234
575645.227659483 3189205.17163764
575641.392720288 3189206.82592006
575637.150456055 3189214.96975033
575633.985427757 3189224.89189997
575630.732860735 3189232.87583130
575629.825200565 3189234.78891918
575626.268606140 3189244.70118035
575625.055756129 3189254.67262378
575624.048800203 3189264.64926620
575626.033070719 3189274.70144150
575628.301047757 3189284.76078116
575629.348139014 3189287.71323321
575630.865563282 3189294.82760927
575632.585061618 3189304.87309963
575633.749353391 3189314.90457031
575634.569486755 3189324.92735054
575636.649511930 3189334.98194565
575638.050011320 3189339.20256643
575640.817786629 3189345.08927361
575647.656595518 3189354.86415159
575647.870775185 3189355.26944727
575654.747228098 3189365.44516408
575657.269399466 3189370.27939153
575662.074406641 3189375.63226375
575667.058357271 3189378.71883487
575674.871973717 3189385.95750447
575676.800091128 3189389.02837035
575684.133094564 3189396.19344337
575686.586685119 3189397.56143505
575696.422894795 3189404.12972127
575700.864844918 3189406.61803541
575706.247405814 3189411.16129194
575715.751567506 3189416.99603830
575716.098781051 3189417.12905527
575726.036514414 3189419.67706070
575736.017098070 3189420.52822388
575745.982395609 3189421.98474492
575756.005774219 3189421.14128728
575766.053610679 3189419.32932771
575769.136073507 3189418.34413225
575776.223506655 3189412.68383576
575779.240944960 3189408.59722472
575786.447078405 3189403.91279079
575796.523744120 3189400.95926314
575799.389111391 3189399.10393297
575805.535189846 3189389.25705318
575806.854089989 3189387.95995545
575816.972618517 3189383.34868686
575819.537289559 3189379.60855471
575822.008081040 3189369.66886365
575827.547621183 3189360.66081291
575828.761131424 3189359.83730830
575836.931299811 3189350.04153712
575837.844535516 3189348.98535223
575840.943246114 3189340.14076154
575843.602853864 3189330.20583632
575846.984577107 3189320.28914546
575848.756275143 3189312.96214604
575850.522840530 3189310.37640707
575854.053180112 3189300.46346810
575854.964811253 3189290.48440209
575851.181415037 3189280.38677937
575849.764141289 3189273.04921042
575849.517599011 3189270.34267971
575843.653125281 3189260.19250792
575840.207154651 3189255.42251920
575835.594666340 3189249.98693602
575830.470162708 3189244.92434067
575823.627599270 3189239.68266813
575820.649830226 3189237.72661781
575810.781232117 3189232.44033033
575805.255617650 3189229.21667049
575800.963379230 3189225.14444292
575791.086532261 3189220.18486820
575787.656625601 3189218.77019437
575781.182921444 3189216.28522513
575771.266091576 3189212.90911181
575761.354718952 3189209.31690449
575758.250526886 3189208.02557942
575751.503530051 3189203.34130216
575741.563262126 3189200.89346790
575731.630100857 3189198.16421964
575727.023285731 3189197.23498323
575721.678739338 3189196.15577354]
data2 = [575731.422838196 3189206.37232435
575724.697961952 3189207.17834314
575721.394010027 3189207.43174664
575711.364654134 3189208.51209622
575701.337970259 3189209.48665581
575691.319597425 3189210.13210704
575681.265867243 3189212.17781946
575671.229649118 3189213.53004162
575661.238791658 3189213.08590592
575651.213949200 3189213.98768238
575647.113409301 3189215.22132567
575640.991573607 3189222.71223818
575639.486204725 3189225.03080093
575630.773146661 3189231.28042522
575626.361206512 3189234.70144909
575620.515832815 3189241.38861678
575619.227201771 3189244.52337575
575615.294804439 3189254.42614638
575611.728754337 3189264.33816728
575610.825894415 3189274.31743727
575610.019497925 3189284.29914302
575612.199764593 3189294.35626689
575614.140766277 3189304.40734924
575616.755327358 3189314.47544050
575618.552527076 3189319.13850901
575621.878551158 3189324.60688061
575628.162248551 3189334.67588513
575628.217729738 3189334.76902672
575635.418719721 3189344.95293626
575637.762350507 3189350.59416235
575640.873491159 3189355.09275120
575647.522419377 3189360.17761406
575652.554788934 3189365.38980024
575657.207443596 3189372.73287452
575660.346312788 3189375.58862551
575667.041781573 3189379.37523935
575673.376126510 3189385.91973087
575676.723934510 3189392.04419395
575680.359244947 3189396.09814467
575686.526280383 3189399.95347416
575693.260598684 3189406.42600951
575696.245920828 3189411.13790683
575701.943322200 3189416.64734516
575706.050815019 3189418.94628958
575715.930434190 3189423.79558285
575723.484025899 3189427.19337957
575725.793998076 3189429.28068546
575735.775124065 3189430.11037054
575745.755309984 3189430.97731069
575750.945388100 3189427.88685048
575755.879236329 3189426.15217806
575765.956578764 3189423.17178706
575776.025683486 3189420.51763495
575779.517405427 3189418.60628718
575785.884931838 3189408.76500175
575786.332681882 3189408.44290783
575796.433874881 3189404.51810025
575806.560091648 3189399.60237019
575808.088283081 3189399.32360785
575816.676357286 3189395.08072864
575819.981180111 3189389.62184792
575826.994371634 3189382.56978788
575832.212012345 3189379.92861994
575837.242777695 3189372.81535473
575838.008516413 3189370.07290944
575840.812110902 3189360.14162087
575842.594128381 3189350.18453504
575847.474455532 3189340.30568737
575848.111345114 3189338.50205485
575854.967611222 3189330.49281788
575855.989375110 3189320.51653295
575857.810750377 3189310.56043949
575854.671003314 3189300.47906917
575852.328243476 3189290.41782454
575849.406644524 3189287.20664394
575845.929355550 3189280.25415686
575841.477934729 3189270.13966651
575839.935268430 3189266.18969967
575834.930938952 3189259.97226068
575830.172676589 3189256.70535602
575823.102617400 3189249.67149545
575820.455440295 3189245.42484822
575813.145830725 3189239.41799054
575810.633609741 3189238.28648202
575800.759767900 3189233.20788699
575791.729334709 3189228.87511614
575790.885959615 3189228.12798485
575781.089451899 3189219.98683027
575777.562658171 3189218.51531071
575771.160574863 3189217.08781557
575761.222464867 3189214.55447377
575751.293622469 3189211.65414062
575741.345269581 3189209.52649525
575734.009662553 3189207.41347302
575731.422838196 3189206.37232435]If I have two data sets(each from xy data) and they are intersect at more than two points, How can I find the area between intersection points? If there are more than one area, i.e., Area1, Area2, etc, I would like to find each area separately and assign +ve and -ve sign to the areas? Figure and Example of my data is below (data1 and data2):
data1 = [575721.678739338 3189196.15577354
575711.702452018 3189195.13447944
575701.688569224 3189195.60208872
575691.697320475 3189195.17336187
575681.678990798 3189195.81713592
575676.797287407 3189195.96672958
575671.667154953 3189196.20376653
575661.619557374 3189198.00667871
575651.499830521 3189202.66611234
575645.227659483 3189205.17163764
575641.392720288 3189206.82592006
575637.150456055 3189214.96975033
575633.985427757 3189224.89189997
575630.732860735 3189232.87583130
575629.825200565 3189234.78891918
575626.268606140 3189244.70118035
575625.055756129 3189254.67262378
575624.048800203 3189264.64926620
575626.033070719 3189274.70144150
575628.301047757 3189284.76078116
575629.348139014 3189287.71323321
575630.865563282 3189294.82760927
575632.585061618 3189304.87309963
575633.749353391 3189314.90457031
575634.569486755 3189324.92735054
575636.649511930 3189334.98194565
575638.050011320 3189339.20256643
575640.817786629 3189345.08927361
575647.656595518 3189354.86415159
575647.870775185 3189355.26944727
575654.747228098 3189365.44516408
575657.269399466 3189370.27939153
575662.074406641 3189375.63226375
575667.058357271 3189378.71883487
575674.871973717 3189385.95750447
575676.800091128 3189389.02837035
575684.133094564 3189396.19344337
575686.586685119 3189397.56143505
575696.422894795 3189404.12972127
575700.864844918 3189406.61803541
575706.247405814 3189411.16129194
575715.751567506 3189416.99603830
575716.098781051 3189417.12905527
575726.036514414 3189419.67706070
575736.017098070 3189420.52822388
575745.982395609 3189421.98474492
575756.005774219 3189421.14128728
575766.053610679 3189419.32932771
575769.136073507 3189418.34413225
575776.223506655 3189412.68383576
575779.240944960 3189408.59722472
575786.447078405 3189403.91279079
575796.523744120 3189400.95926314
575799.389111391 3189399.10393297
575805.535189846 3189389.25705318
575806.854089989 3189387.95995545
575816.972618517 3189383.34868686
575819.537289559 3189379.60855471
575822.008081040 3189369.66886365
575827.547621183 3189360.66081291
575828.761131424 3189359.83730830
575836.931299811 3189350.04153712
575837.844535516 3189348.98535223
575840.943246114 3189340.14076154
575843.602853864 3189330.20583632
575846.984577107 3189320.28914546
575848.756275143 3189312.96214604
575850.522840530 3189310.37640707
575854.053180112 3189300.46346810
575854.964811253 3189290.48440209
575851.181415037 3189280.38677937
575849.764141289 3189273.04921042
575849.517599011 3189270.34267971
575843.653125281 3189260.19250792
575840.207154651 3189255.42251920
575835.594666340 3189249.98693602
575830.470162708 3189244.92434067
575823.627599270 3189239.68266813
575820.649830226 3189237.72661781
575810.781232117 3189232.44033033
575805.255617650 3189229.21667049
575800.963379230 3189225.14444292
575791.086532261 3189220.18486820
575787.656625601 3189218.77019437
575781.182921444 3189216.28522513
575771.266091576 3189212.90911181
575761.354718952 3189209.31690449
575758.250526886 3189208.02557942
575751.503530051 3189203.34130216
575741.563262126 3189200.89346790
575731.630100857 3189198.16421964
575727.023285731 3189197.23498323
575721.678739338 3189196.15577354]
data2 = [575731.422838196 3189206.37232435
575724.697961952 3189207.17834314
575721.394010027 3189207.43174664
575711.364654134 3189208.51209622
575701.337970259 3189209.48665581
575691.319597425 3189210.13210704
575681.265867243 3189212.17781946
575671.229649118 3189213.53004162
575661.238791658 3189213.08590592
575651.213949200 3189213.98768238
575647.113409301 3189215.22132567
575640.991573607 3189222.71223818
575639.486204725 3189225.03080093
575630.773146661 3189231.28042522
575626.361206512 3189234.70144909
575620.515832815 3189241.38861678
575619.227201771 3189244.52337575
575615.294804439 3189254.42614638
575611.728754337 3189264.33816728
575610.825894415 3189274.31743727
575610.019497925 3189284.29914302
575612.199764593 3189294.35626689
575614.140766277 3189304.40734924
575616.755327358 3189314.47544050
575618.552527076 3189319.13850901
575621.878551158 3189324.60688061
575628.162248551 3189334.67588513
575628.217729738 3189334.76902672
575635.418719721 3189344.95293626
575637.762350507 3189350.59416235
575640.873491159 3189355.09275120
575647.522419377 3189360.17761406
575652.554788934 3189365.38980024
575657.207443596 3189372.73287452
575660.346312788 3189375.58862551
575667.041781573 3189379.37523935
575673.376126510 3189385.91973087
575676.723934510 3189392.04419395
575680.359244947 3189396.09814467
575686.526280383 3189399.95347416
575693.260598684 3189406.42600951
575696.245920828 3189411.13790683
575701.943322200 3189416.64734516
575706.050815019 3189418.94628958
575715.930434190 3189423.79558285
575723.484025899 3189427.19337957
575725.793998076 3189429.28068546
575735.775124065 3189430.11037054
575745.755309984 3189430.97731069
575750.945388100 3189427.88685048
575755.879236329 3189426.15217806
575765.956578764 3189423.17178706
575776.025683486 3189420.51763495
575779.517405427 3189418.60628718
575785.884931838 3189408.76500175
575786.332681882 3189408.44290783
575796.433874881 3189404.51810025
575806.560091648 3189399.60237019
575808.088283081 3189399.32360785
575816.676357286 3189395.08072864
575819.981180111 3189389.62184792
575826.994371634 3189382.56978788
575832.212012345 3189379.92861994
575837.242777695 3189372.81535473
575838.008516413 3189370.07290944
575840.812110902 3189360.14162087
575842.594128381 3189350.18453504
575847.474455532 3189340.30568737
575848.111345114 3189338.50205485
575854.967611222 3189330.49281788
575855.989375110 3189320.51653295
575857.810750377 3189310.56043949
575854.671003314 3189300.47906917
575852.328243476 3189290.41782454
575849.406644524 3189287.20664394
575845.929355550 3189280.25415686
575841.477934729 3189270.13966651
575839.935268430 3189266.18969967
575834.930938952 3189259.97226068
575830.172676589 3189256.70535602
575823.102617400 3189249.67149545
575820.455440295 3189245.42484822
575813.145830725 3189239.41799054
575810.633609741 3189238.28648202
575800.759767900 3189233.20788699
575791.729334709 3189228.87511614
575790.885959615 3189228.12798485
575781.089451899 3189219.98683027
575777.562658171 3189218.51531071
575771.160574863 3189217.08781557
575761.222464867 3189214.55447377
575751.293622469 3189211.65414062
575741.345269581 3189209.52649525
575734.009662553 3189207.41347302
575731.422838196 3189206.37232435] If I have two data sets(each from xy data) and they are intersect at more than two points, How can I find the area between intersection points? If there are more than one area, i.e., Area1, Area2, etc, I would like to find each area separately and assign +ve and -ve sign to the areas? Figure and Example of my data is below (data1 and data2):
data1 = [575721.678739338 3189196.15577354
575711.702452018 3189195.13447944
575701.688569224 3189195.60208872
575691.697320475 3189195.17336187
575681.678990798 3189195.81713592
575676.797287407 3189195.96672958
575671.667154953 3189196.20376653
575661.619557374 3189198.00667871
575651.499830521 3189202.66611234
575645.227659483 3189205.17163764
575641.392720288 3189206.82592006
575637.150456055 3189214.96975033
575633.985427757 3189224.89189997
575630.732860735 3189232.87583130
575629.825200565 3189234.78891918
575626.268606140 3189244.70118035
575625.055756129 3189254.67262378
575624.048800203 3189264.64926620
575626.033070719 3189274.70144150
575628.301047757 3189284.76078116
575629.348139014 3189287.71323321
575630.865563282 3189294.82760927
575632.585061618 3189304.87309963
575633.749353391 3189314.90457031
575634.569486755 3189324.92735054
575636.649511930 3189334.98194565
575638.050011320 3189339.20256643
575640.817786629 3189345.08927361
575647.656595518 3189354.86415159
575647.870775185 3189355.26944727
575654.747228098 3189365.44516408
575657.269399466 3189370.27939153
575662.074406641 3189375.63226375
575667.058357271 3189378.71883487
575674.871973717 3189385.95750447
575676.800091128 3189389.02837035
575684.133094564 3189396.19344337
575686.586685119 3189397.56143505
575696.422894795 3189404.12972127
575700.864844918 3189406.61803541
575706.247405814 3189411.16129194
575715.751567506 3189416.99603830
575716.098781051 3189417.12905527
575726.036514414 3189419.67706070
575736.017098070 3189420.52822388
575745.982395609 3189421.98474492
575756.005774219 3189421.14128728
575766.053610679 3189419.32932771
575769.136073507 3189418.34413225
575776.223506655 3189412.68383576
575779.240944960 3189408.59722472
575786.447078405 3189403.91279079
575796.523744120 3189400.95926314
575799.389111391 3189399.10393297
575805.535189846 3189389.25705318
575806.854089989 3189387.95995545
575816.972618517 3189383.34868686
575819.537289559 3189379.60855471
575822.008081040 3189369.66886365
575827.547621183 3189360.66081291
575828.761131424 3189359.83730830
575836.931299811 3189350.04153712
575837.844535516 3189348.98535223
575840.943246114 3189340.14076154
575843.602853864 3189330.20583632
575846.984577107 3189320.28914546
575848.756275143 3189312.96214604
575850.522840530 3189310.37640707
575854.053180112 3189300.46346810
575854.964811253 3189290.48440209
575851.181415037 3189280.38677937
575849.764141289 3189273.04921042
575849.517599011 3189270.34267971
575843.653125281 3189260.19250792
575840.207154651 3189255.42251920
575835.594666340 3189249.98693602
575830.470162708 3189244.92434067
575823.627599270 3189239.68266813
575820.649830226 3189237.72661781
575810.781232117 3189232.44033033
575805.255617650 3189229.21667049
575800.963379230 3189225.14444292
575791.086532261 3189220.18486820
575787.656625601 3189218.77019437
575781.182921444 3189216.28522513
575771.266091576 3189212.90911181
575761.354718952 3189209.31690449
575758.250526886 3189208.02557942
575751.503530051 3189203.34130216
575741.563262126 3189200.89346790
575731.630100857 3189198.16421964
575727.023285731 3189197.23498323
575721.678739338 3189196.15577354]
data2 = [575731.422838196 3189206.37232435
575724.697961952 3189207.17834314
575721.394010027 3189207.43174664
575711.364654134 3189208.51209622
575701.337970259 3189209.48665581
575691.319597425 3189210.13210704
575681.265867243 3189212.17781946
575671.229649118 3189213.53004162
575661.238791658 3189213.08590592
575651.213949200 3189213.98768238
575647.113409301 3189215.22132567
575640.991573607 3189222.71223818
575639.486204725 3189225.03080093
575630.773146661 3189231.28042522
575626.361206512 3189234.70144909
575620.515832815 3189241.38861678
575619.227201771 3189244.52337575
575615.294804439 3189254.42614638
575611.728754337 3189264.33816728
575610.825894415 3189274.31743727
575610.019497925 3189284.29914302
575612.199764593 3189294.35626689
575614.140766277 3189304.40734924
575616.755327358 3189314.47544050
575618.552527076 3189319.13850901
575621.878551158 3189324.60688061
575628.162248551 3189334.67588513
575628.217729738 3189334.76902672
575635.418719721 3189344.95293626
575637.762350507 3189350.59416235
575640.873491159 3189355.09275120
575647.522419377 3189360.17761406
575652.554788934 3189365.38980024
575657.207443596 3189372.73287452
575660.346312788 3189375.58862551
575667.041781573 3189379.37523935
575673.376126510 3189385.91973087
575676.723934510 3189392.04419395
575680.359244947 3189396.09814467
575686.526280383 3189399.95347416
575693.260598684 3189406.42600951
575696.245920828 3189411.13790683
575701.943322200 3189416.64734516
575706.050815019 3189418.94628958
575715.930434190 3189423.79558285
575723.484025899 3189427.19337957
575725.793998076 3189429.28068546
575735.775124065 3189430.11037054
575745.755309984 3189430.97731069
575750.945388100 3189427.88685048
575755.879236329 3189426.15217806
575765.956578764 3189423.17178706
575776.025683486 3189420.51763495
575779.517405427 3189418.60628718
575785.884931838 3189408.76500175
575786.332681882 3189408.44290783
575796.433874881 3189404.51810025
575806.560091648 3189399.60237019
575808.088283081 3189399.32360785
575816.676357286 3189395.08072864
575819.981180111 3189389.62184792
575826.994371634 3189382.56978788
575832.212012345 3189379.92861994
575837.242777695 3189372.81535473
575838.008516413 3189370.07290944
575840.812110902 3189360.14162087
575842.594128381 3189350.18453504
575847.474455532 3189340.30568737
575848.111345114 3189338.50205485
575854.967611222 3189330.49281788
575855.989375110 3189320.51653295
575857.810750377 3189310.56043949
575854.671003314 3189300.47906917
575852.328243476 3189290.41782454
575849.406644524 3189287.20664394
575845.929355550 3189280.25415686
575841.477934729 3189270.13966651
575839.935268430 3189266.18969967
575834.930938952 3189259.97226068
575830.172676589 3189256.70535602
575823.102617400 3189249.67149545
575820.455440295 3189245.42484822
575813.145830725 3189239.41799054
575810.633609741 3189238.28648202
575800.759767900 3189233.20788699
575791.729334709 3189228.87511614
575790.885959615 3189228.12798485
575781.089451899 3189219.98683027
575777.562658171 3189218.51531071
575771.160574863 3189217.08781557
575761.222464867 3189214.55447377
575751.293622469 3189211.65414062
575741.345269581 3189209.52649525
575734.009662553 3189207.41347302
575731.422838196 3189206.37232435] area, intersection points MATLAB Answers — New Questions
There is some problem with insertshape function in my matlab program
% Define area threshold (e.g., 100 pixels)
areaThreshold = 500; % Set your desired threshold value here
% Read the TIFF image
image = imread(‘quartz1.tif’);
% Convert to grayscale if not already
if size(image, 3) == 3
grayImage = rgb2gray(image);
else
grayImage = image;
end
% Apply Gaussian blur
blurredImage = imgaussfilt(grayImage, 2);
% Enhance contrast
enhancedImage = imadjust(blurredImage);
% Apply sharpening
sharpenedImage = imsharpen(enhancedImage);
% Detect edges
edges = edge(sharpenedImage, ‘Canny’);
% Find contours
contours = bwconncomp(edges);
% Calculate properties for each grain
stats = regionprops(contours, ‘Area’, ‘Perimeter’, ‘MajorAxisLength’, ‘MinorAxisLength’, ‘Orientation’, ‘BoundingBox’, ‘PixelIdxList’, ‘Centroid’);
% Process each grain
for i = 1:length(stats)
if stats(i).Area > areaThreshold
% Get the bounding box for each grain
bb = stats(i).BoundingBox;
grainRegion = imcrop(grayImage, bb);
% Create a new image to draw axes
grainImageWithAxes = cat(3, grainRegion, grainRegion, grainRegion);
% Get the ellipse properties
orientation = stats(i).Orientation;
majorAxisLength = stats(i).MajorAxisLength;
minorAxisLength = stats(i).MinorAxisLength;
perimeter = stats(i).Perimeter; % Perimeter value
centerX = stats(i).Centroid(1) – bb(1);
centerY = stats(i).Centroid(2) – bb(2);
% Compute the endpoints of the major and minor axes
majorAxisEnd1 = [centerX + majorAxisLength / 2 * cosd(orientation), centerY – majorAxisLength / 2 * sind(orientation)];
majorAxisEnd2 = [centerX – majorAxisLength / 2 * cosd(orientation), centerY + majorAxisLength / 2 * sind(orientation)];
minorAxisEnd1 = [centerX + minorAxisLength / 2 * cosd(orientation + 90), centerY – minorAxisLength / 2 * sind(orientation + 90)];
minorAxisEnd2 = [centerX – minorAxisLength / 2 * cosd(orientation + 90), centerY + minorAxisLength / 2 * sind(orientation + 90)];
% Ensure endpoints are within bounds of the image
majorAxisEnd1 = max(min(majorAxisEnd1, size(grainRegion, 2) – 1), 1);
majorAxisEnd2 = max(min(majorAxisEnd2, size(grainRegion, 2) – 1), 1);
minorAxisEnd1 = max(min(minorAxisEnd1, size(grainRegion, 2) – 1), 1);
minorAxisEnd2 = max(min(minorAxisEnd2, size(grainRegion, 2) – 1), 1);
% Draw the axes
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Line’, [majorAxisEnd1, majorAxisEnd2], ‘Color’, ‘red’, ‘LineWidth’, 3);
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Line’, [minorAxisEnd1, minorAxisEnd2], ‘Color’, ‘blue’, ‘LineWidth’, 3);
% Draw contour (perimeter)
contour = bwboundaries(contours.PixelIdxList{i});
contourVertices = contour{1} – [bb(1), bb(2)];
% Convert contourVertices to a cell array with one matrix
contourVerticesCell = {contourVertices};
% Draw the contour
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Polygon’, ‘Vertices’, {contourVertices}, ‘Color’, ‘green’, ‘LineWidth’, 2);
% Add text annotations with larger font size
grainImageWithAxes = insertText(grainImageWithAxes, [10 10], sprintf(‘Major Axis: %.2f’, majorAxisLength), ‘FontSize’, 12, ‘TextColor’, ‘red’, ‘BoxColor’, ‘black’);
grainImageWithAxes = insertText(grainImageWithAxes, [10 30], sprintf(‘Minor Axis: %.2f’, minorAxisLength), ‘FontSize’, 12, ‘TextColor’, ‘blue’, ‘BoxColor’, ‘black’);
grainImageWithAxes = insertText(grainImageWithAxes, [10 50], sprintf(‘Perimeter: %.2f’, perimeter), ‘FontSize’, 12, ‘TextColor’, ‘green’, ‘BoxColor’, ‘black’);
% Save the image with axes using PNG format
filename = sprintf(‘grain_%d_axes.png’, i);
imwrite(grainImageWithAxes, filename, ‘PNG’);
% Display the image with axes
figure;
imshow(grainImageWithAxes);
title(sprintf(‘Sand Grain %d’, i));
end
end
the error i am getting is
Error using insertShape
Expected POSITION to be one of these types:
cell
Error in insertShape>checkPosition (line 332)
validateattributes(position,{‘cell’}, {‘nonempty’, ‘vector’}, …
Error in insertShape>validateAndParseInputs (line 256)
checkPosition(position, shape1);
Error in insertShape (line 129)
validateAndParseInputs(I, shape, position, varargin{:});
Error in untitled8 (line 74)
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Polygon’, ‘Vertices’, {contourVertices}, ‘Color’, ‘green’, ‘LineWidth’, 2);% Define area threshold (e.g., 100 pixels)
areaThreshold = 500; % Set your desired threshold value here
% Read the TIFF image
image = imread(‘quartz1.tif’);
% Convert to grayscale if not already
if size(image, 3) == 3
grayImage = rgb2gray(image);
else
grayImage = image;
end
% Apply Gaussian blur
blurredImage = imgaussfilt(grayImage, 2);
% Enhance contrast
enhancedImage = imadjust(blurredImage);
% Apply sharpening
sharpenedImage = imsharpen(enhancedImage);
% Detect edges
edges = edge(sharpenedImage, ‘Canny’);
% Find contours
contours = bwconncomp(edges);
% Calculate properties for each grain
stats = regionprops(contours, ‘Area’, ‘Perimeter’, ‘MajorAxisLength’, ‘MinorAxisLength’, ‘Orientation’, ‘BoundingBox’, ‘PixelIdxList’, ‘Centroid’);
% Process each grain
for i = 1:length(stats)
if stats(i).Area > areaThreshold
% Get the bounding box for each grain
bb = stats(i).BoundingBox;
grainRegion = imcrop(grayImage, bb);
% Create a new image to draw axes
grainImageWithAxes = cat(3, grainRegion, grainRegion, grainRegion);
% Get the ellipse properties
orientation = stats(i).Orientation;
majorAxisLength = stats(i).MajorAxisLength;
minorAxisLength = stats(i).MinorAxisLength;
perimeter = stats(i).Perimeter; % Perimeter value
centerX = stats(i).Centroid(1) – bb(1);
centerY = stats(i).Centroid(2) – bb(2);
% Compute the endpoints of the major and minor axes
majorAxisEnd1 = [centerX + majorAxisLength / 2 * cosd(orientation), centerY – majorAxisLength / 2 * sind(orientation)];
majorAxisEnd2 = [centerX – majorAxisLength / 2 * cosd(orientation), centerY + majorAxisLength / 2 * sind(orientation)];
minorAxisEnd1 = [centerX + minorAxisLength / 2 * cosd(orientation + 90), centerY – minorAxisLength / 2 * sind(orientation + 90)];
minorAxisEnd2 = [centerX – minorAxisLength / 2 * cosd(orientation + 90), centerY + minorAxisLength / 2 * sind(orientation + 90)];
% Ensure endpoints are within bounds of the image
majorAxisEnd1 = max(min(majorAxisEnd1, size(grainRegion, 2) – 1), 1);
majorAxisEnd2 = max(min(majorAxisEnd2, size(grainRegion, 2) – 1), 1);
minorAxisEnd1 = max(min(minorAxisEnd1, size(grainRegion, 2) – 1), 1);
minorAxisEnd2 = max(min(minorAxisEnd2, size(grainRegion, 2) – 1), 1);
% Draw the axes
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Line’, [majorAxisEnd1, majorAxisEnd2], ‘Color’, ‘red’, ‘LineWidth’, 3);
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Line’, [minorAxisEnd1, minorAxisEnd2], ‘Color’, ‘blue’, ‘LineWidth’, 3);
% Draw contour (perimeter)
contour = bwboundaries(contours.PixelIdxList{i});
contourVertices = contour{1} – [bb(1), bb(2)];
% Convert contourVertices to a cell array with one matrix
contourVerticesCell = {contourVertices};
% Draw the contour
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Polygon’, ‘Vertices’, {contourVertices}, ‘Color’, ‘green’, ‘LineWidth’, 2);
% Add text annotations with larger font size
grainImageWithAxes = insertText(grainImageWithAxes, [10 10], sprintf(‘Major Axis: %.2f’, majorAxisLength), ‘FontSize’, 12, ‘TextColor’, ‘red’, ‘BoxColor’, ‘black’);
grainImageWithAxes = insertText(grainImageWithAxes, [10 30], sprintf(‘Minor Axis: %.2f’, minorAxisLength), ‘FontSize’, 12, ‘TextColor’, ‘blue’, ‘BoxColor’, ‘black’);
grainImageWithAxes = insertText(grainImageWithAxes, [10 50], sprintf(‘Perimeter: %.2f’, perimeter), ‘FontSize’, 12, ‘TextColor’, ‘green’, ‘BoxColor’, ‘black’);
% Save the image with axes using PNG format
filename = sprintf(‘grain_%d_axes.png’, i);
imwrite(grainImageWithAxes, filename, ‘PNG’);
% Display the image with axes
figure;
imshow(grainImageWithAxes);
title(sprintf(‘Sand Grain %d’, i));
end
end
the error i am getting is
Error using insertShape
Expected POSITION to be one of these types:
cell
Error in insertShape>checkPosition (line 332)
validateattributes(position,{‘cell’}, {‘nonempty’, ‘vector’}, …
Error in insertShape>validateAndParseInputs (line 256)
checkPosition(position, shape1);
Error in insertShape (line 129)
validateAndParseInputs(I, shape, position, varargin{:});
Error in untitled8 (line 74)
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Polygon’, ‘Vertices’, {contourVertices}, ‘Color’, ‘green’, ‘LineWidth’, 2); % Define area threshold (e.g., 100 pixels)
areaThreshold = 500; % Set your desired threshold value here
% Read the TIFF image
image = imread(‘quartz1.tif’);
% Convert to grayscale if not already
if size(image, 3) == 3
grayImage = rgb2gray(image);
else
grayImage = image;
end
% Apply Gaussian blur
blurredImage = imgaussfilt(grayImage, 2);
% Enhance contrast
enhancedImage = imadjust(blurredImage);
% Apply sharpening
sharpenedImage = imsharpen(enhancedImage);
% Detect edges
edges = edge(sharpenedImage, ‘Canny’);
% Find contours
contours = bwconncomp(edges);
% Calculate properties for each grain
stats = regionprops(contours, ‘Area’, ‘Perimeter’, ‘MajorAxisLength’, ‘MinorAxisLength’, ‘Orientation’, ‘BoundingBox’, ‘PixelIdxList’, ‘Centroid’);
% Process each grain
for i = 1:length(stats)
if stats(i).Area > areaThreshold
% Get the bounding box for each grain
bb = stats(i).BoundingBox;
grainRegion = imcrop(grayImage, bb);
% Create a new image to draw axes
grainImageWithAxes = cat(3, grainRegion, grainRegion, grainRegion);
% Get the ellipse properties
orientation = stats(i).Orientation;
majorAxisLength = stats(i).MajorAxisLength;
minorAxisLength = stats(i).MinorAxisLength;
perimeter = stats(i).Perimeter; % Perimeter value
centerX = stats(i).Centroid(1) – bb(1);
centerY = stats(i).Centroid(2) – bb(2);
% Compute the endpoints of the major and minor axes
majorAxisEnd1 = [centerX + majorAxisLength / 2 * cosd(orientation), centerY – majorAxisLength / 2 * sind(orientation)];
majorAxisEnd2 = [centerX – majorAxisLength / 2 * cosd(orientation), centerY + majorAxisLength / 2 * sind(orientation)];
minorAxisEnd1 = [centerX + minorAxisLength / 2 * cosd(orientation + 90), centerY – minorAxisLength / 2 * sind(orientation + 90)];
minorAxisEnd2 = [centerX – minorAxisLength / 2 * cosd(orientation + 90), centerY + minorAxisLength / 2 * sind(orientation + 90)];
% Ensure endpoints are within bounds of the image
majorAxisEnd1 = max(min(majorAxisEnd1, size(grainRegion, 2) – 1), 1);
majorAxisEnd2 = max(min(majorAxisEnd2, size(grainRegion, 2) – 1), 1);
minorAxisEnd1 = max(min(minorAxisEnd1, size(grainRegion, 2) – 1), 1);
minorAxisEnd2 = max(min(minorAxisEnd2, size(grainRegion, 2) – 1), 1);
% Draw the axes
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Line’, [majorAxisEnd1, majorAxisEnd2], ‘Color’, ‘red’, ‘LineWidth’, 3);
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Line’, [minorAxisEnd1, minorAxisEnd2], ‘Color’, ‘blue’, ‘LineWidth’, 3);
% Draw contour (perimeter)
contour = bwboundaries(contours.PixelIdxList{i});
contourVertices = contour{1} – [bb(1), bb(2)];
% Convert contourVertices to a cell array with one matrix
contourVerticesCell = {contourVertices};
% Draw the contour
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Polygon’, ‘Vertices’, {contourVertices}, ‘Color’, ‘green’, ‘LineWidth’, 2);
% Add text annotations with larger font size
grainImageWithAxes = insertText(grainImageWithAxes, [10 10], sprintf(‘Major Axis: %.2f’, majorAxisLength), ‘FontSize’, 12, ‘TextColor’, ‘red’, ‘BoxColor’, ‘black’);
grainImageWithAxes = insertText(grainImageWithAxes, [10 30], sprintf(‘Minor Axis: %.2f’, minorAxisLength), ‘FontSize’, 12, ‘TextColor’, ‘blue’, ‘BoxColor’, ‘black’);
grainImageWithAxes = insertText(grainImageWithAxes, [10 50], sprintf(‘Perimeter: %.2f’, perimeter), ‘FontSize’, 12, ‘TextColor’, ‘green’, ‘BoxColor’, ‘black’);
% Save the image with axes using PNG format
filename = sprintf(‘grain_%d_axes.png’, i);
imwrite(grainImageWithAxes, filename, ‘PNG’);
% Display the image with axes
figure;
imshow(grainImageWithAxes);
title(sprintf(‘Sand Grain %d’, i));
end
end
the error i am getting is
Error using insertShape
Expected POSITION to be one of these types:
cell
Error in insertShape>checkPosition (line 332)
validateattributes(position,{‘cell’}, {‘nonempty’, ‘vector’}, …
Error in insertShape>validateAndParseInputs (line 256)
checkPosition(position, shape1);
Error in insertShape (line 129)
validateAndParseInputs(I, shape, position, varargin{:});
Error in untitled8 (line 74)
grainImageWithAxes = insertShape(grainImageWithAxes, ‘Polygon’, ‘Vertices’, {contourVertices}, ‘Color’, ‘green’, ‘LineWidth’, 2); insertshape MATLAB Answers — New Questions
Problem Using the Median Function with Complex Numbers
Hello,
I encounter an issue with the median function when using on complex numbers. I am using MATLAB 2022a. In the link: https://www.mathworks.com/matlabcentral/answers/96926-why-do-i-receive-different-results-when-applying-median-or-nanmedian-to-my-matrix-vs-a-single-colu#answer_106277 it is stated that the median function sorts the complex numbers according to their magnitudes. However, I tried the median function with the abs values of the complex numbers after seeing that the numbers are not like what I expected. In my case, computing the median then the magnitude and the reverse (computing the absolute values of an array then the median) did not produce the same result where it should have produced. With further debug in the built-in function median, I observed that this case occurs when the length of the array is an even number. I think that the problem is due to the function that calculates the mean (inside the median) for the two middle numbers. The function is:
function c = meanof(a,b)
% MEANOF the mean of A and B with B > A
% MEANOF calculates the mean of A and B. It uses different formula
% in order to avoid overflow in floating point arithmetic.
if islogical(a)
c = a | b;
else
if isinteger(a)
% Swap integers such that ABS(B) > ABS(A), for correct rounding
ind = b < 0;
temp = a(ind);
a(ind) = b(ind);
b(ind) = temp;
end
c = a + (b-a)/2;
k = (sign(a) ~= sign(b)) | isinf(a) | isinf(b);
c(k) = (a(k)+b(k))/2;
end
In the bold part, c is calculated as (a+b)/2. Then, according to k, it should be updated as c(k) = (a(k)-b(k))/2 to correct the calculation if the numbers have different signs whereas it remains the same since it is given as c(k) = (a(k)+b(k))/2.
Thank you in advance.Hello,
I encounter an issue with the median function when using on complex numbers. I am using MATLAB 2022a. In the link: https://www.mathworks.com/matlabcentral/answers/96926-why-do-i-receive-different-results-when-applying-median-or-nanmedian-to-my-matrix-vs-a-single-colu#answer_106277 it is stated that the median function sorts the complex numbers according to their magnitudes. However, I tried the median function with the abs values of the complex numbers after seeing that the numbers are not like what I expected. In my case, computing the median then the magnitude and the reverse (computing the absolute values of an array then the median) did not produce the same result where it should have produced. With further debug in the built-in function median, I observed that this case occurs when the length of the array is an even number. I think that the problem is due to the function that calculates the mean (inside the median) for the two middle numbers. The function is:
function c = meanof(a,b)
% MEANOF the mean of A and B with B > A
% MEANOF calculates the mean of A and B. It uses different formula
% in order to avoid overflow in floating point arithmetic.
if islogical(a)
c = a | b;
else
if isinteger(a)
% Swap integers such that ABS(B) > ABS(A), for correct rounding
ind = b < 0;
temp = a(ind);
a(ind) = b(ind);
b(ind) = temp;
end
c = a + (b-a)/2;
k = (sign(a) ~= sign(b)) | isinf(a) | isinf(b);
c(k) = (a(k)+b(k))/2;
end
In the bold part, c is calculated as (a+b)/2. Then, according to k, it should be updated as c(k) = (a(k)-b(k))/2 to correct the calculation if the numbers have different signs whereas it remains the same since it is given as c(k) = (a(k)+b(k))/2.
Thank you in advance. Hello,
I encounter an issue with the median function when using on complex numbers. I am using MATLAB 2022a. In the link: https://www.mathworks.com/matlabcentral/answers/96926-why-do-i-receive-different-results-when-applying-median-or-nanmedian-to-my-matrix-vs-a-single-colu#answer_106277 it is stated that the median function sorts the complex numbers according to their magnitudes. However, I tried the median function with the abs values of the complex numbers after seeing that the numbers are not like what I expected. In my case, computing the median then the magnitude and the reverse (computing the absolute values of an array then the median) did not produce the same result where it should have produced. With further debug in the built-in function median, I observed that this case occurs when the length of the array is an even number. I think that the problem is due to the function that calculates the mean (inside the median) for the two middle numbers. The function is:
function c = meanof(a,b)
% MEANOF the mean of A and B with B > A
% MEANOF calculates the mean of A and B. It uses different formula
% in order to avoid overflow in floating point arithmetic.
if islogical(a)
c = a | b;
else
if isinteger(a)
% Swap integers such that ABS(B) > ABS(A), for correct rounding
ind = b < 0;
temp = a(ind);
a(ind) = b(ind);
b(ind) = temp;
end
c = a + (b-a)/2;
k = (sign(a) ~= sign(b)) | isinf(a) | isinf(b);
c(k) = (a(k)+b(k))/2;
end
In the bold part, c is calculated as (a+b)/2. Then, according to k, it should be updated as c(k) = (a(k)-b(k))/2 to correct the calculation if the numbers have different signs whereas it remains the same since it is given as c(k) = (a(k)+b(k))/2.
Thank you in advance. digital signal processing, embedded matlab function MATLAB Answers — New Questions