Category: Matlab
Category Archives: Matlab
make figure spectrogram as length as signal above it
I would like to put spectogram result below the signal figure. I use specgram (in second row) and spectogram result in last row, but i get difficulties to make the lenght of spectogram, figure as length as signal figure. Can somebody help me?I would like to put spectogram result below the signal figure. I use specgram (in second row) and spectogram result in last row, but i get difficulties to make the lenght of spectogram, figure as length as signal figure. Can somebody help me? I would like to put spectogram result below the signal figure. I use specgram (in second row) and spectogram result in last row, but i get difficulties to make the lenght of spectogram, figure as length as signal figure. Can somebody help me? spectrogram, figure expand MATLAB Answers — New Questions
How do I access the prompt location property in masks programmatically?
I am looking for a way to set the Prompt Location property of a mask programmatically.I could not find it in the following doc:
https://www.mathworks.com/help/simulink/slref/simulink.mask.simulink.mask.addparameter.htmlI am looking for a way to set the Prompt Location property of a mask programmatically.I could not find it in the following doc:
https://www.mathworks.com/help/simulink/slref/simulink.mask.simulink.mask.addparameter.html I am looking for a way to set the Prompt Location property of a mask programmatically.I could not find it in the following doc:
https://www.mathworks.com/help/simulink/slref/simulink.mask.simulink.mask.addparameter.html MATLAB Answers — New Questions
curve fit a lorentzian
I need to curve fit a lorentzian but the curve fitting tool does not have the appropriate option. Does someone have an .m file for fitting lorentzian.
ThanksI need to curve fit a lorentzian but the curve fitting tool does not have the appropriate option. Does someone have an .m file for fitting lorentzian.
Thanks I need to curve fit a lorentzian but the curve fitting tool does not have the appropriate option. Does someone have an .m file for fitting lorentzian.
Thanks lorentzian, curve fitting MATLAB Answers — New Questions
How can i change ppm image resolution when I using Imread?
For example,
a = imread("xxxx.ppm")
xxxx image resolution has default 255
So when I reading 1023 resolution ppm files, data is forcibly multiplied by 20.
How can I change ppm image resolution when I Using Imread?
please help me,
I’m sorry for the lack of readability because My English skill are not good
Thanks for reading.For example,
a = imread("xxxx.ppm")
xxxx image resolution has default 255
So when I reading 1023 resolution ppm files, data is forcibly multiplied by 20.
How can I change ppm image resolution when I Using Imread?
please help me,
I’m sorry for the lack of readability because My English skill are not good
Thanks for reading. For example,
a = imread("xxxx.ppm")
xxxx image resolution has default 255
So when I reading 1023 resolution ppm files, data is forcibly multiplied by 20.
How can I change ppm image resolution when I Using Imread?
please help me,
I’m sorry for the lack of readability because My English skill are not good
Thanks for reading. imread, ppm, resolution MATLAB Answers — New Questions
measuring resistance in simulink
Hi everyone. There is such a basic circuit I need to model. It has only three resistors without any voltage source. I couldn’t find any ohmmeter in simulink. How can I measure the equivalent resistance?Hi everyone. There is such a basic circuit I need to model. It has only three resistors without any voltage source. I couldn’t find any ohmmeter in simulink. How can I measure the equivalent resistance? Hi everyone. There is such a basic circuit I need to model. It has only three resistors without any voltage source. I couldn’t find any ohmmeter in simulink. How can I measure the equivalent resistance? ohmmeter MATLAB Answers — New Questions
obtain AIC value for each copula
hi, good morning. I need to compare the different copulas to figure out which one fits the data best. To do this I have to calculate the IAC for each copula. Can anyone tell me how I can implement this calculation? A thousand thanks
%copula Gaussiana
[grho]=copulafit(‘Gaussian’,[vu2 vu4])
rho = grho(1,2)
cm = 10 % number of evaluation
d = linspace(0,1,cm);
[u2,u4] = meshgrid(d,d);
u = copularnd(‘Gaussian’,rho,n);hi, good morning. I need to compare the different copulas to figure out which one fits the data best. To do this I have to calculate the IAC for each copula. Can anyone tell me how I can implement this calculation? A thousand thanks
%copula Gaussiana
[grho]=copulafit(‘Gaussian’,[vu2 vu4])
rho = grho(1,2)
cm = 10 % number of evaluation
d = linspace(0,1,cm);
[u2,u4] = meshgrid(d,d);
u = copularnd(‘Gaussian’,rho,n); hi, good morning. I need to compare the different copulas to figure out which one fits the data best. To do this I have to calculate the IAC for each copula. Can anyone tell me how I can implement this calculation? A thousand thanks
%copula Gaussiana
[grho]=copulafit(‘Gaussian’,[vu2 vu4])
rho = grho(1,2)
cm = 10 % number of evaluation
d = linspace(0,1,cm);
[u2,u4] = meshgrid(d,d);
u = copularnd(‘Gaussian’,rho,n); aic, copula MATLAB Answers — New Questions
我从pytorch中导入net到工作区,在把net导入到simulink中的matlab function中,在运行过程中出现如下问题Code generation for custom layer ‘aten__linear0’ for target ‘mkldnn’ is not supported as it returns a dlarra
classdef aten__linear0 < nnet.layer.Layer & nnet.layer.Formattable & …
nnet.layer.AutogeneratedFromPyTorch & nnet.layer.Acceleratable
%aten__linear0 Auto-generated custom layer
% Auto-generated by MATLAB on 2024-05-24 16:18:35
%#codegen
properties (Learnable)
% Networks (type dlnetwork)
end
properties
% Non-Trainable Parameters
end
properties (Learnable)
% Trainable Parameters
Param_weight
Param_bias
end
methods
function obj = aten__linear0(Name, Type, InputNames, OutputNames)
obj.Name = Name;
obj.Type = Type;
obj.NumInputs = 1;
obj.NumOutputs = 1;
obj.InputNames = InputNames;
obj.OutputNames = OutputNames;
end
function [linear_9] = predict(obj,linear_x_1)
%Validates that the input has the correct format and permutes its dimensions into the reverse of the original PyTorch format.
model_tt.ops.validateInput(linear_x_1,2);
[linear_x_1, linear_x_1_format] = model_tt.ops.permuteInputToReversePyTorch(linear_x_1, 2);
[linear_x_1] = struct(‘value’, linear_x_1, ‘rank’, int64(2));
[linear_9] = tracedPyTorchFunction(obj,linear_x_1,false,"predict");
%Permute U-labelled output to forward PyTorch dimension ordering
if(any(dims(linear_9.value) == ‘U’))
linear_9 = permute(linear_9.value, fliplr(1:max(2,linear_9.rank)));
end
end
function [linear_9] = forward(obj,linear_x_1)
%Validates that the input has the correct format and permutes its dimensions into the reverse of the original PyTorch format.
model_tt.ops.validateInput(linear_x_1,2);
[linear_x_1, linear_x_1_format] = model_tt.ops.permuteInputToReversePyTorch(linear_x_1, 2);
[linear_x_1] = struct(‘value’, linear_x_1, ‘rank’, int64(2));
[linear_9] = tracedPyTorchFunction(obj,linear_x_1,true,"forward");
%Permute U-labelled output to forward PyTorch dimension ordering
if(any(dims(linear_9.value) == ‘U’))
linear_9 = permute(linear_9.value, fliplr(1:max(2,linear_9.rank)));
end
end
function [linear_9] = tracedPyTorchFunction(obj,linear_x_1,isForward,predict)
linear_weight_1 = obj.Param_weight;
[linear_weight_1] = struct(‘value’, dlarray(linear_weight_1,’UU’), ‘rank’, 2);
linear_bias_1 = obj.Param_bias;
[linear_bias_1] = struct(‘value’, dlarray(linear_bias_1,’UU’), ‘rank’, 1);
[linear_9] = model_tt.ops.pyLinear(linear_x_1, linear_weight_1, linear_bias_1);
end
end
endclassdef aten__linear0 < nnet.layer.Layer & nnet.layer.Formattable & …
nnet.layer.AutogeneratedFromPyTorch & nnet.layer.Acceleratable
%aten__linear0 Auto-generated custom layer
% Auto-generated by MATLAB on 2024-05-24 16:18:35
%#codegen
properties (Learnable)
% Networks (type dlnetwork)
end
properties
% Non-Trainable Parameters
end
properties (Learnable)
% Trainable Parameters
Param_weight
Param_bias
end
methods
function obj = aten__linear0(Name, Type, InputNames, OutputNames)
obj.Name = Name;
obj.Type = Type;
obj.NumInputs = 1;
obj.NumOutputs = 1;
obj.InputNames = InputNames;
obj.OutputNames = OutputNames;
end
function [linear_9] = predict(obj,linear_x_1)
%Validates that the input has the correct format and permutes its dimensions into the reverse of the original PyTorch format.
model_tt.ops.validateInput(linear_x_1,2);
[linear_x_1, linear_x_1_format] = model_tt.ops.permuteInputToReversePyTorch(linear_x_1, 2);
[linear_x_1] = struct(‘value’, linear_x_1, ‘rank’, int64(2));
[linear_9] = tracedPyTorchFunction(obj,linear_x_1,false,"predict");
%Permute U-labelled output to forward PyTorch dimension ordering
if(any(dims(linear_9.value) == ‘U’))
linear_9 = permute(linear_9.value, fliplr(1:max(2,linear_9.rank)));
end
end
function [linear_9] = forward(obj,linear_x_1)
%Validates that the input has the correct format and permutes its dimensions into the reverse of the original PyTorch format.
model_tt.ops.validateInput(linear_x_1,2);
[linear_x_1, linear_x_1_format] = model_tt.ops.permuteInputToReversePyTorch(linear_x_1, 2);
[linear_x_1] = struct(‘value’, linear_x_1, ‘rank’, int64(2));
[linear_9] = tracedPyTorchFunction(obj,linear_x_1,true,"forward");
%Permute U-labelled output to forward PyTorch dimension ordering
if(any(dims(linear_9.value) == ‘U’))
linear_9 = permute(linear_9.value, fliplr(1:max(2,linear_9.rank)));
end
end
function [linear_9] = tracedPyTorchFunction(obj,linear_x_1,isForward,predict)
linear_weight_1 = obj.Param_weight;
[linear_weight_1] = struct(‘value’, dlarray(linear_weight_1,’UU’), ‘rank’, 2);
linear_bias_1 = obj.Param_bias;
[linear_bias_1] = struct(‘value’, dlarray(linear_bias_1,’UU’), ‘rank’, 1);
[linear_9] = model_tt.ops.pyLinear(linear_x_1, linear_weight_1, linear_bias_1);
end
end
end classdef aten__linear0 < nnet.layer.Layer & nnet.layer.Formattable & …
nnet.layer.AutogeneratedFromPyTorch & nnet.layer.Acceleratable
%aten__linear0 Auto-generated custom layer
% Auto-generated by MATLAB on 2024-05-24 16:18:35
%#codegen
properties (Learnable)
% Networks (type dlnetwork)
end
properties
% Non-Trainable Parameters
end
properties (Learnable)
% Trainable Parameters
Param_weight
Param_bias
end
methods
function obj = aten__linear0(Name, Type, InputNames, OutputNames)
obj.Name = Name;
obj.Type = Type;
obj.NumInputs = 1;
obj.NumOutputs = 1;
obj.InputNames = InputNames;
obj.OutputNames = OutputNames;
end
function [linear_9] = predict(obj,linear_x_1)
%Validates that the input has the correct format and permutes its dimensions into the reverse of the original PyTorch format.
model_tt.ops.validateInput(linear_x_1,2);
[linear_x_1, linear_x_1_format] = model_tt.ops.permuteInputToReversePyTorch(linear_x_1, 2);
[linear_x_1] = struct(‘value’, linear_x_1, ‘rank’, int64(2));
[linear_9] = tracedPyTorchFunction(obj,linear_x_1,false,"predict");
%Permute U-labelled output to forward PyTorch dimension ordering
if(any(dims(linear_9.value) == ‘U’))
linear_9 = permute(linear_9.value, fliplr(1:max(2,linear_9.rank)));
end
end
function [linear_9] = forward(obj,linear_x_1)
%Validates that the input has the correct format and permutes its dimensions into the reverse of the original PyTorch format.
model_tt.ops.validateInput(linear_x_1,2);
[linear_x_1, linear_x_1_format] = model_tt.ops.permuteInputToReversePyTorch(linear_x_1, 2);
[linear_x_1] = struct(‘value’, linear_x_1, ‘rank’, int64(2));
[linear_9] = tracedPyTorchFunction(obj,linear_x_1,true,"forward");
%Permute U-labelled output to forward PyTorch dimension ordering
if(any(dims(linear_9.value) == ‘U’))
linear_9 = permute(linear_9.value, fliplr(1:max(2,linear_9.rank)));
end
end
function [linear_9] = tracedPyTorchFunction(obj,linear_x_1,isForward,predict)
linear_weight_1 = obj.Param_weight;
[linear_weight_1] = struct(‘value’, dlarray(linear_weight_1,’UU’), ‘rank’, 2);
linear_bias_1 = obj.Param_bias;
[linear_bias_1] = struct(‘value’, dlarray(linear_bias_1,’UU’), ‘rank’, 1);
[linear_9] = model_tt.ops.pyLinear(linear_x_1, linear_weight_1, linear_bias_1);
end
end
end simulink, neural network MATLAB Answers — New Questions
Figure Not Displaying Properly
Hello, I’m messing around with different slices of the brain, as shown below. Each image is essentially a 2D array visualized using imagesc, where each "pixel" corresponds to an element of the array. However, the subplots don’t appear to be scaling properly at all. Both the sagittal and coronal slice are 140 elements "tall", however because I assume MATLAB individually scales each subplot a certain way, they do not appear to be as tall as each other whatsoever. Similarly, the transverse slice should be as tall as the sagittal slice is wide (and the coronal slice should be as tall as the transverse slice is wide), but not of these dimensions match up. Here is a snippet of my code for troubleshooting purposes:
% sagittal slice, 165×140 2D array. for recreation purposes,
% you could functionally just make an 165×140 random matrix
ax1 = subplot(1, 3, 1);
imagesc(squeeze(maxS));
colormap(flipud(gray));
title("Sagittal View");
axis off;
axis image;
% coronal slice, 124×140 2D array
ax2 = subplot(1, 3, 2);
imagesc(squeeze(maxC));
colormap(flipud(gray));
title("Coronal View");
axis off;
axis image;
% transverse slice, 165×124 2D array
ax3 = subplot(1, 3, 3);
imagesc(maxT);
colormap(flipud(gray));
title("Transverse View");
axis off;
axis image;
Any and all help would be greatly appreciated. Thank you.Hello, I’m messing around with different slices of the brain, as shown below. Each image is essentially a 2D array visualized using imagesc, where each "pixel" corresponds to an element of the array. However, the subplots don’t appear to be scaling properly at all. Both the sagittal and coronal slice are 140 elements "tall", however because I assume MATLAB individually scales each subplot a certain way, they do not appear to be as tall as each other whatsoever. Similarly, the transverse slice should be as tall as the sagittal slice is wide (and the coronal slice should be as tall as the transverse slice is wide), but not of these dimensions match up. Here is a snippet of my code for troubleshooting purposes:
% sagittal slice, 165×140 2D array. for recreation purposes,
% you could functionally just make an 165×140 random matrix
ax1 = subplot(1, 3, 1);
imagesc(squeeze(maxS));
colormap(flipud(gray));
title("Sagittal View");
axis off;
axis image;
% coronal slice, 124×140 2D array
ax2 = subplot(1, 3, 2);
imagesc(squeeze(maxC));
colormap(flipud(gray));
title("Coronal View");
axis off;
axis image;
% transverse slice, 165×124 2D array
ax3 = subplot(1, 3, 3);
imagesc(maxT);
colormap(flipud(gray));
title("Transverse View");
axis off;
axis image;
Any and all help would be greatly appreciated. Thank you. Hello, I’m messing around with different slices of the brain, as shown below. Each image is essentially a 2D array visualized using imagesc, where each "pixel" corresponds to an element of the array. However, the subplots don’t appear to be scaling properly at all. Both the sagittal and coronal slice are 140 elements "tall", however because I assume MATLAB individually scales each subplot a certain way, they do not appear to be as tall as each other whatsoever. Similarly, the transverse slice should be as tall as the sagittal slice is wide (and the coronal slice should be as tall as the transverse slice is wide), but not of these dimensions match up. Here is a snippet of my code for troubleshooting purposes:
% sagittal slice, 165×140 2D array. for recreation purposes,
% you could functionally just make an 165×140 random matrix
ax1 = subplot(1, 3, 1);
imagesc(squeeze(maxS));
colormap(flipud(gray));
title("Sagittal View");
axis off;
axis image;
% coronal slice, 124×140 2D array
ax2 = subplot(1, 3, 2);
imagesc(squeeze(maxC));
colormap(flipud(gray));
title("Coronal View");
axis off;
axis image;
% transverse slice, 165×124 2D array
ax3 = subplot(1, 3, 3);
imagesc(maxT);
colormap(flipud(gray));
title("Transverse View");
axis off;
axis image;
Any and all help would be greatly appreciated. Thank you. figure MATLAB Answers — New Questions
App not supported on Apple Silicon
Was trying to use Transmission Line app on M2 Air but got an error saying it isn’t supported on apple silicon. I’m currently installing it on parallels so I know all of the features and apps work, but is there a way to get it to work on Mac? I’d hate to have to run a VM for MATLAB.
Thank you.Was trying to use Transmission Line app on M2 Air but got an error saying it isn’t supported on apple silicon. I’m currently installing it on parallels so I know all of the features and apps work, but is there a way to get it to work on Mac? I’d hate to have to run a VM for MATLAB.
Thank you. Was trying to use Transmission Line app on M2 Air but got an error saying it isn’t supported on apple silicon. I’m currently installing it on parallels so I know all of the features and apps work, but is there a way to get it to work on Mac? I’d hate to have to run a VM for MATLAB.
Thank you. mac, m2, rf toolbox MATLAB Answers — New Questions
How can I programmatically modify an Excel file with AIP sensitivity tags?
My company has recently decided to make Excel create files automatically with Azure Information Protection (AIP) sensitivity labels. We have programs in MATLAB that modify Excel files, but because of this, they have started to fail when trying to modify the files. Specifically, when using the writetable function, MATLAB shows the following error:
Unable to write to file ‘D:Prueba xlswriteBenchmark_Colones_1-2años_31-03-2024.xlsx’.
Ensure the file is a valid spreadsheet file and is not password protected.
Is there a way to programmatically provide the credentials needed by Excel to be able to modify the file when it is allowed?My company has recently decided to make Excel create files automatically with Azure Information Protection (AIP) sensitivity labels. We have programs in MATLAB that modify Excel files, but because of this, they have started to fail when trying to modify the files. Specifically, when using the writetable function, MATLAB shows the following error:
Unable to write to file ‘D:Prueba xlswriteBenchmark_Colones_1-2años_31-03-2024.xlsx’.
Ensure the file is a valid spreadsheet file and is not password protected.
Is there a way to programmatically provide the credentials needed by Excel to be able to modify the file when it is allowed? My company has recently decided to make Excel create files automatically with Azure Information Protection (AIP) sensitivity labels. We have programs in MATLAB that modify Excel files, but because of this, they have started to fail when trying to modify the files. Specifically, when using the writetable function, MATLAB shows the following error:
Unable to write to file ‘D:Prueba xlswriteBenchmark_Colones_1-2años_31-03-2024.xlsx’.
Ensure the file is a valid spreadsheet file and is not password protected.
Is there a way to programmatically provide the credentials needed by Excel to be able to modify the file when it is allowed? writetable, excel, aip MATLAB Answers — New Questions
how can i apply for a paid internship or job
hi my name is andres ima undergrad student currently in UMASS boston and im in need of a job or at least an internship to gain some experience as a software engineer or data analyst i am a veteran and i would like to join mathworks in my state is there a place i can go apply or talk to someone? thank you so much. heres my contact information andres.gamboa001@umb.edu
number is 508-494-0584
sincerely andres gamboahi my name is andres ima undergrad student currently in UMASS boston and im in need of a job or at least an internship to gain some experience as a software engineer or data analyst i am a veteran and i would like to join mathworks in my state is there a place i can go apply or talk to someone? thank you so much. heres my contact information andres.gamboa001@umb.edu
number is 508-494-0584
sincerely andres gamboa hi my name is andres ima undergrad student currently in UMASS boston and im in need of a job or at least an internship to gain some experience as a software engineer or data analyst i am a veteran and i would like to join mathworks in my state is there a place i can go apply or talk to someone? thank you so much. heres my contact information andres.gamboa001@umb.edu
number is 508-494-0584
sincerely andres gamboa job MATLAB Answers — New Questions
Complex value computed by model function, fitting cannot continue. Try using or tightening upper and lower bounds on coefficients.
Hello, I really need some help on data fitting. I would like to fit my data custom equation:a+b*exp((-(x/c))^d. I try to use upper and lower bounds on coefficients but it does not work.If anyone can tell me what to do to resolve this I would greatly appreciate it.Hello, I really need some help on data fitting. I would like to fit my data custom equation:a+b*exp((-(x/c))^d. I try to use upper and lower bounds on coefficients but it does not work.If anyone can tell me what to do to resolve this I would greatly appreciate it. Hello, I really need some help on data fitting. I would like to fit my data custom equation:a+b*exp((-(x/c))^d. I try to use upper and lower bounds on coefficients but it does not work.If anyone can tell me what to do to resolve this I would greatly appreciate it. curve fitting, data fitting MATLAB Answers — New Questions
How to Generate Smooth Transitional Trapezoidal Signal in Simulink
Hi, everyone. I want to generate a custom signal demonstrated as follow image in Simulink, I have tried the Signal Editor Block, but the generated trapezoidal signal does not have smooth transition as showed in the attached image.
I would be appreciated that someone could give me some suggestions.Hi, everyone. I want to generate a custom signal demonstrated as follow image in Simulink, I have tried the Signal Editor Block, but the generated trapezoidal signal does not have smooth transition as showed in the attached image.
I would be appreciated that someone could give me some suggestions. Hi, everyone. I want to generate a custom signal demonstrated as follow image in Simulink, I have tried the Signal Editor Block, but the generated trapezoidal signal does not have smooth transition as showed in the attached image.
I would be appreciated that someone could give me some suggestions. signal generation, trapezoidal signal, simulink MATLAB Answers — New Questions
Matlab is not recognizing sections %%
I am working with Matlab 2018a and for some reason Matlab stop recognizing my sections (%%). Maybe I did something after messing in Home>Preferences, but I’m not really sure. Has anyone had this problem before? I’ve look online and people say "Enable Cell Mode", but I have no idea how to do this in 2018a.
thanks in advance.I am working with Matlab 2018a and for some reason Matlab stop recognizing my sections (%%). Maybe I did something after messing in Home>Preferences, but I’m not really sure. Has anyone had this problem before? I’ve look online and people say "Enable Cell Mode", but I have no idea how to do this in 2018a.
thanks in advance. I am working with Matlab 2018a and for some reason Matlab stop recognizing my sections (%%). Maybe I did something after messing in Home>Preferences, but I’m not really sure. Has anyone had this problem before? I’ve look online and people say "Enable Cell Mode", but I have no idea how to do this in 2018a.
thanks in advance. sections MATLAB Answers — New Questions
Drawing the major and minor axis of an elliptical object in Matlab
This program currently inputs an image of a coin, thresholds it, binarizes it, and finds the major and minor axis lengths of the segmented elliptical using the regionprops function. What I want to do is output a subplot where I draw the axes used to calculate the ‘MajorAxisLength’ and ‘MinorAxisLength’ over the original image. Would really appreciate help with this.
I have appended the code for your perusal.
rgbImage = imread(coin2.jpg);
subplot(2, 3, 1);
imshow(rgbImage, []);
title(‘Original Image’);
redChannel = rgbImage(:, :, 1);
binaryImage = redChannel < 100;
subplot(2, 3, 3);
imshow(binaryImage, []);
title(‘Binarized Image’);
labeledImage = bwlabel(binaryImage);
area_measurements = regionprops(labeledImage,’Area’);
allAreas = [area_measurements.Area];
biggestBlobIndex = find(allAreas == max(allAreas));
keeperBlobsImage = ismember(labeledImage, biggestBlobIndex);
measurements = regionprops(keeperBlobsImage,’MajorAxisLength’,’MinorAxisLength’)
% Display the original color image with outline.
subplot(2, 3, 4);
imshow(rgbImage);
hold on;
title(‘Original Color Image with Outline’, ‘FontSize’,fontSize);
boundaries = bwboundaries(keeperBlobsImage);
blobBoundary = boundaries{1};
plot(blobBoundary(:,2), blobBoundary(:,1), ‘g-‘, ‘LineWidth’, 1);
hold off;This program currently inputs an image of a coin, thresholds it, binarizes it, and finds the major and minor axis lengths of the segmented elliptical using the regionprops function. What I want to do is output a subplot where I draw the axes used to calculate the ‘MajorAxisLength’ and ‘MinorAxisLength’ over the original image. Would really appreciate help with this.
I have appended the code for your perusal.
rgbImage = imread(coin2.jpg);
subplot(2, 3, 1);
imshow(rgbImage, []);
title(‘Original Image’);
redChannel = rgbImage(:, :, 1);
binaryImage = redChannel < 100;
subplot(2, 3, 3);
imshow(binaryImage, []);
title(‘Binarized Image’);
labeledImage = bwlabel(binaryImage);
area_measurements = regionprops(labeledImage,’Area’);
allAreas = [area_measurements.Area];
biggestBlobIndex = find(allAreas == max(allAreas));
keeperBlobsImage = ismember(labeledImage, biggestBlobIndex);
measurements = regionprops(keeperBlobsImage,’MajorAxisLength’,’MinorAxisLength’)
% Display the original color image with outline.
subplot(2, 3, 4);
imshow(rgbImage);
hold on;
title(‘Original Color Image with Outline’, ‘FontSize’,fontSize);
boundaries = bwboundaries(keeperBlobsImage);
blobBoundary = boundaries{1};
plot(blobBoundary(:,2), blobBoundary(:,1), ‘g-‘, ‘LineWidth’, 1);
hold off; This program currently inputs an image of a coin, thresholds it, binarizes it, and finds the major and minor axis lengths of the segmented elliptical using the regionprops function. What I want to do is output a subplot where I draw the axes used to calculate the ‘MajorAxisLength’ and ‘MinorAxisLength’ over the original image. Would really appreciate help with this.
I have appended the code for your perusal.
rgbImage = imread(coin2.jpg);
subplot(2, 3, 1);
imshow(rgbImage, []);
title(‘Original Image’);
redChannel = rgbImage(:, :, 1);
binaryImage = redChannel < 100;
subplot(2, 3, 3);
imshow(binaryImage, []);
title(‘Binarized Image’);
labeledImage = bwlabel(binaryImage);
area_measurements = regionprops(labeledImage,’Area’);
allAreas = [area_measurements.Area];
biggestBlobIndex = find(allAreas == max(allAreas));
keeperBlobsImage = ismember(labeledImage, biggestBlobIndex);
measurements = regionprops(keeperBlobsImage,’MajorAxisLength’,’MinorAxisLength’)
% Display the original color image with outline.
subplot(2, 3, 4);
imshow(rgbImage);
hold on;
title(‘Original Color Image with Outline’, ‘FontSize’,fontSize);
boundaries = bwboundaries(keeperBlobsImage);
blobBoundary = boundaries{1};
plot(blobBoundary(:,2), blobBoundary(:,1), ‘g-‘, ‘LineWidth’, 1);
hold off; matlab, image-processing MATLAB Answers — New Questions
How to remove trailing zeros while display any floating point number ?
format short g;
X=input (‘any>’);
%if input is 93.93
disp (X);
It display 93.930
How to disp 93.93
I can’t remove
format short g;
Bcz of another mathematical reasons and calculations…format short g;
X=input (‘any>’);
%if input is 93.93
disp (X);
It display 93.930
How to disp 93.93
I can’t remove
format short g;
Bcz of another mathematical reasons and calculations… format short g;
X=input (‘any>’);
%if input is 93.93
disp (X);
It display 93.930
How to disp 93.93
I can’t remove
format short g;
Bcz of another mathematical reasons and calculations… zeros, format MATLAB Answers — New Questions
System Requirements – x86-64 and OpenGL version
I have two questions about the system requirements listed here:
https://au.mathworks.com/support/requirements/matlab-system-requirements.html
1) How do I tell if a processor is "x86-64" type. I suspect they all are these days, but they either don’t bother putting it in the specs list or use a different term.
2) Will it work just as well with an OpenGL version greater than 3.3? EG 4.6?I have two questions about the system requirements listed here:
https://au.mathworks.com/support/requirements/matlab-system-requirements.html
1) How do I tell if a processor is "x86-64" type. I suspect they all are these days, but they either don’t bother putting it in the specs list or use a different term.
2) Will it work just as well with an OpenGL version greater than 3.3? EG 4.6? I have two questions about the system requirements listed here:
https://au.mathworks.com/support/requirements/matlab-system-requirements.html
1) How do I tell if a processor is "x86-64" type. I suspect they all are these days, but they either don’t bother putting it in the specs list or use a different term.
2) Will it work just as well with an OpenGL version greater than 3.3? EG 4.6? system requirements, x86-64, opengl MATLAB Answers — New Questions
How to report/flag a user or a ThingSpeak channel?
When I find spammers, I often tend to check their profile to see what else needs cleaned up. Occasionally there are accounts like these:
https://www.mathworks.com/matlabcentral/profile/authors/32134539
https://www.mathworks.com/matlabcentral/profile/authors/34100453
Both of these accounts had been pasting dumb exploit attempts on either the forum or FEX, which have since been deleted. In both cases though, they left behind some extra trash on ThingSpeak.
The problem is that I see no way to report content on ThingSpeak, and the Report button rarely shows up on user profile pages. For me, in Firefox, only the second profile page has one.
As far as I’m concerned, there’s no point keeping these disposed spam accounts around, so I’m not terribly concerned with reporting the ThingSpeak channels. I just want to know how to report/flag the accounts when the button won’t show up. I guess let’s start with figuring out whether I’m the only one that can’t see the button.When I find spammers, I often tend to check their profile to see what else needs cleaned up. Occasionally there are accounts like these:
https://www.mathworks.com/matlabcentral/profile/authors/32134539
https://www.mathworks.com/matlabcentral/profile/authors/34100453
Both of these accounts had been pasting dumb exploit attempts on either the forum or FEX, which have since been deleted. In both cases though, they left behind some extra trash on ThingSpeak.
The problem is that I see no way to report content on ThingSpeak, and the Report button rarely shows up on user profile pages. For me, in Firefox, only the second profile page has one.
As far as I’m concerned, there’s no point keeping these disposed spam accounts around, so I’m not terribly concerned with reporting the ThingSpeak channels. I just want to know how to report/flag the accounts when the button won’t show up. I guess let’s start with figuring out whether I’m the only one that can’t see the button. When I find spammers, I often tend to check their profile to see what else needs cleaned up. Occasionally there are accounts like these:
https://www.mathworks.com/matlabcentral/profile/authors/32134539
https://www.mathworks.com/matlabcentral/profile/authors/34100453
Both of these accounts had been pasting dumb exploit attempts on either the forum or FEX, which have since been deleted. In both cases though, they left behind some extra trash on ThingSpeak.
The problem is that I see no way to report content on ThingSpeak, and the Report button rarely shows up on user profile pages. For me, in Firefox, only the second profile page has one.
As far as I’m concerned, there’s no point keeping these disposed spam accounts around, so I’m not terribly concerned with reporting the ThingSpeak channels. I just want to know how to report/flag the accounts when the button won’t show up. I guess let’s start with figuring out whether I’m the only one that can’t see the button. meta MATLAB Answers — New Questions
solving 1D drift diffusion model for a semiconductor using FDTD. Can anyone rectify this error.
% Constants and parameters
q = 1.602e-19; % elementary charge
k = 1.38e-23; % Boltzmann constant
eps0 = 8.85e-12; % vacuum permittivity
epsr = 11.7; % relative permittivity of silicon
Na = 1e17; % doping concentration (p-type)
L = 1e-6; % length of the semiconductor
mu_e = 1000*1e-4; % electron mobility
mu_h = 1000*1e-4; % hole mobility
D_e = k*300*mu_e/q; % electron diffusion coefficient
D_h = k*300*mu_h/q; % hole diffusion coefficient
T = 300; % temperature
V = 0.1; % applied voltage
% Spatial and time parameters
nx = 100; % number of spatial grid points
dx = L/nx; % spatial step
dt = 1e-9; % time step
nt = 100; % number of time steps
% Initialize carrier densities and electric potential
n = zeros(nx, 1); % electron density
p = zeros(nx, 1); % hole density
phi = zeros(nx, 1); % electric potential
phi(1) = V; % boundary condition at x=0
% Simulation loop
for t = 1:nt
% Calculate electric field
E = -(phi(2:end) – phi(1:end-1))/dx;
% Calculate electron and hole densities
Jn = q*D_e*(n(3:end) – n(2:end-1))/dx – q*mu_e*E.*n(2:end-1);
Jp = q*D_h*(p(3:end) – p(2:end-1))/dx + q*mu_h*E.*p(2:end-1);
% Update carrier densities
n(2:end-1) = n(2:end-1) + dt*Na./(1+exp((phi(2:end-1)-V/2)/(k*T))) – dt*Jn;
p(2:end-1) = p(2:end-1) + dt*Na./(1+exp((V/2-phi(2:end-1))/(k*T))) – dt*Jp;
% Update electric potential
rho = q*(Na – n – p); % charge density
phi(2:end-1) = phi(2:end-1) + dt*1/(epsr*eps0)*rho(2:end-1);
end% Constants and parameters
q = 1.602e-19; % elementary charge
k = 1.38e-23; % Boltzmann constant
eps0 = 8.85e-12; % vacuum permittivity
epsr = 11.7; % relative permittivity of silicon
Na = 1e17; % doping concentration (p-type)
L = 1e-6; % length of the semiconductor
mu_e = 1000*1e-4; % electron mobility
mu_h = 1000*1e-4; % hole mobility
D_e = k*300*mu_e/q; % electron diffusion coefficient
D_h = k*300*mu_h/q; % hole diffusion coefficient
T = 300; % temperature
V = 0.1; % applied voltage
% Spatial and time parameters
nx = 100; % number of spatial grid points
dx = L/nx; % spatial step
dt = 1e-9; % time step
nt = 100; % number of time steps
% Initialize carrier densities and electric potential
n = zeros(nx, 1); % electron density
p = zeros(nx, 1); % hole density
phi = zeros(nx, 1); % electric potential
phi(1) = V; % boundary condition at x=0
% Simulation loop
for t = 1:nt
% Calculate electric field
E = -(phi(2:end) – phi(1:end-1))/dx;
% Calculate electron and hole densities
Jn = q*D_e*(n(3:end) – n(2:end-1))/dx – q*mu_e*E.*n(2:end-1);
Jp = q*D_h*(p(3:end) – p(2:end-1))/dx + q*mu_h*E.*p(2:end-1);
% Update carrier densities
n(2:end-1) = n(2:end-1) + dt*Na./(1+exp((phi(2:end-1)-V/2)/(k*T))) – dt*Jn;
p(2:end-1) = p(2:end-1) + dt*Na./(1+exp((V/2-phi(2:end-1))/(k*T))) – dt*Jp;
% Update electric potential
rho = q*(Na – n – p); % charge density
phi(2:end-1) = phi(2:end-1) + dt*1/(epsr*eps0)*rho(2:end-1);
end % Constants and parameters
q = 1.602e-19; % elementary charge
k = 1.38e-23; % Boltzmann constant
eps0 = 8.85e-12; % vacuum permittivity
epsr = 11.7; % relative permittivity of silicon
Na = 1e17; % doping concentration (p-type)
L = 1e-6; % length of the semiconductor
mu_e = 1000*1e-4; % electron mobility
mu_h = 1000*1e-4; % hole mobility
D_e = k*300*mu_e/q; % electron diffusion coefficient
D_h = k*300*mu_h/q; % hole diffusion coefficient
T = 300; % temperature
V = 0.1; % applied voltage
% Spatial and time parameters
nx = 100; % number of spatial grid points
dx = L/nx; % spatial step
dt = 1e-9; % time step
nt = 100; % number of time steps
% Initialize carrier densities and electric potential
n = zeros(nx, 1); % electron density
p = zeros(nx, 1); % hole density
phi = zeros(nx, 1); % electric potential
phi(1) = V; % boundary condition at x=0
% Simulation loop
for t = 1:nt
% Calculate electric field
E = -(phi(2:end) – phi(1:end-1))/dx;
% Calculate electron and hole densities
Jn = q*D_e*(n(3:end) – n(2:end-1))/dx – q*mu_e*E.*n(2:end-1);
Jp = q*D_h*(p(3:end) – p(2:end-1))/dx + q*mu_h*E.*p(2:end-1);
% Update carrier densities
n(2:end-1) = n(2:end-1) + dt*Na./(1+exp((phi(2:end-1)-V/2)/(k*T))) – dt*Jn;
p(2:end-1) = p(2:end-1) + dt*Na./(1+exp((V/2-phi(2:end-1))/(k*T))) – dt*Jp;
% Update electric potential
rho = q*(Na – n – p); % charge density
phi(2:end-1) = phi(2:end-1) + dt*1/(epsr*eps0)*rho(2:end-1);
end fdtd, drift diffusion model MATLAB Answers — New Questions
pearsrnd and pearspdf are not coherent for the Pearson IV distribution?
We are having some trouble using the Pearson 4 implementation of the functions pearsrnd, pearspdf and pearscdf.
We think that pearsrnd does not generate samples from the distribution defined in pearspdf. In particular, we’ve found that pearsrnd over generates observations in the tails of the distribution.
In order to see this, we’ve implemented two simple tests:
1. We’ve compared the PDF of the Pearson 4 distribution (using pearspdf) to the PDF obtained from a simulation using pearsrnd, but we’ve found that the two are very different (even with a very long sample). This problem doesn’t happen for other distributions. In particular, we’ve implemented the same test with the Pearson 6, and the results are satisfactory.
2. In addition, to test if the generatated sample is compatible with its CDF, we’ve applied the function pearscdf to the generated sample. We should have got a uniform distribution, because if X is a random variable and F its CDF, then F(X) is uniform in [0,1]. This is indeed what we’ve got with the Pearson 6, as expected, but not what we’ve got using the Pearson 4.
We’ve conducted a similar experiment using Mathematica, and we get the correct result.
We’ve attached the code we’ve used.
Any idea why we’re getting this result?
Thank you very much.
%% Seed
rng(123)
%% Parameters
%Type IV
mu4 = 5;
sigma4 = 1;
skew4 = 1;
kurt4 = 10;
% Check the distribution type
[ign, type4] = pearsrnd(mu4, sigma4, skew4, kurt4, 1);
disp("This Pearson is of type " + type4)
% Type VI
mu6 = 2;
sigma6 = 1;
skew6 = 2;
kurt6 = 10;
% Check the distribution type
[ign, type6] = pearsrnd(mu6, sigma6, skew6, kurt6, 1);
disp("This Pearson is of type " + type6)
%% Simulate n observations according to both Pearson distributions defined above
n = 100000;
samples4 = pearsrnd(mu4, sigma4, skew4, kurt4, 1, n);
samples6 = pearsrnd(mu6, sigma6, skew6, kurt6, 1, n);
%% First test: we compare the simulated pdf (i.e. histogram of the sample) to the closed form PDF
pdf4 = @(x) pearspdf(x, mu4, sigma4, skew4, kurt4);
pdf6 = @(x) pearspdf(x, mu6, sigma6, skew6, kurt6);
x_ = linspace(-10, 10, 10000);
y4 = pdf4(x_);
y6 = pdf6(x_);
figure(‘Position’, [100, 100, 1000, 400]); % [left, bottom, width, height]
subplot(1, 2, 1);
plot(x_, y4, Color=’red’, LineWidth=2)
title(‘Simulated and closed form PDF for Pearson 4’)
hold on
histogram(samples4, 1000, ‘Normalization’, ‘pdf’, ‘FaceColor’, ‘blue’)
hold off
subplot(1, 2, 2);
plot(x_, y6, Color=’red’, LineWidth=2)
title(‘Simulated and closed form PDF for Pearson 6’)
hold on
histogram(samples6, 1000, ‘Normalization’, ‘pdf’, ‘FaceColor’, ‘blue’)
hold off
sgtitle(‘Test 1: Comparison between Pearson 4 and 6’);
%% Second test: Let X be a random variable and F its CDF, then F(X) is uniform in [0,1].
% We apply the Pearson CDF to the simulated observations and plot its
% histogram. We should obtain something resembling a uniform distribution.
figure(‘Position’, [100, 100, 1000, 400]); % [left, bottom, width, height]
subplot(1, 2, 1);
u4 = pearscdf(samples4, mu4, sigma4, skew4, kurt4);
histogram(u4)
title(‘F(X) for Pearson 4’)
subplot(1, 2, 2);
u6 = pearscdf(samples6, mu6, sigma6, skew6, kurt6);
histogram(u6)
title(‘F(X) for Pearson 6’)
sgtitle(‘Test 2: Comparison between Pearson 4 and 6’);
%% Conclusion
%We get the expected results using the Pearson 6, but we cannot say the
%same for the Pearson 4. Why?We are having some trouble using the Pearson 4 implementation of the functions pearsrnd, pearspdf and pearscdf.
We think that pearsrnd does not generate samples from the distribution defined in pearspdf. In particular, we’ve found that pearsrnd over generates observations in the tails of the distribution.
In order to see this, we’ve implemented two simple tests:
1. We’ve compared the PDF of the Pearson 4 distribution (using pearspdf) to the PDF obtained from a simulation using pearsrnd, but we’ve found that the two are very different (even with a very long sample). This problem doesn’t happen for other distributions. In particular, we’ve implemented the same test with the Pearson 6, and the results are satisfactory.
2. In addition, to test if the generatated sample is compatible with its CDF, we’ve applied the function pearscdf to the generated sample. We should have got a uniform distribution, because if X is a random variable and F its CDF, then F(X) is uniform in [0,1]. This is indeed what we’ve got with the Pearson 6, as expected, but not what we’ve got using the Pearson 4.
We’ve conducted a similar experiment using Mathematica, and we get the correct result.
We’ve attached the code we’ve used.
Any idea why we’re getting this result?
Thank you very much.
%% Seed
rng(123)
%% Parameters
%Type IV
mu4 = 5;
sigma4 = 1;
skew4 = 1;
kurt4 = 10;
% Check the distribution type
[ign, type4] = pearsrnd(mu4, sigma4, skew4, kurt4, 1);
disp("This Pearson is of type " + type4)
% Type VI
mu6 = 2;
sigma6 = 1;
skew6 = 2;
kurt6 = 10;
% Check the distribution type
[ign, type6] = pearsrnd(mu6, sigma6, skew6, kurt6, 1);
disp("This Pearson is of type " + type6)
%% Simulate n observations according to both Pearson distributions defined above
n = 100000;
samples4 = pearsrnd(mu4, sigma4, skew4, kurt4, 1, n);
samples6 = pearsrnd(mu6, sigma6, skew6, kurt6, 1, n);
%% First test: we compare the simulated pdf (i.e. histogram of the sample) to the closed form PDF
pdf4 = @(x) pearspdf(x, mu4, sigma4, skew4, kurt4);
pdf6 = @(x) pearspdf(x, mu6, sigma6, skew6, kurt6);
x_ = linspace(-10, 10, 10000);
y4 = pdf4(x_);
y6 = pdf6(x_);
figure(‘Position’, [100, 100, 1000, 400]); % [left, bottom, width, height]
subplot(1, 2, 1);
plot(x_, y4, Color=’red’, LineWidth=2)
title(‘Simulated and closed form PDF for Pearson 4’)
hold on
histogram(samples4, 1000, ‘Normalization’, ‘pdf’, ‘FaceColor’, ‘blue’)
hold off
subplot(1, 2, 2);
plot(x_, y6, Color=’red’, LineWidth=2)
title(‘Simulated and closed form PDF for Pearson 6’)
hold on
histogram(samples6, 1000, ‘Normalization’, ‘pdf’, ‘FaceColor’, ‘blue’)
hold off
sgtitle(‘Test 1: Comparison between Pearson 4 and 6’);
%% Second test: Let X be a random variable and F its CDF, then F(X) is uniform in [0,1].
% We apply the Pearson CDF to the simulated observations and plot its
% histogram. We should obtain something resembling a uniform distribution.
figure(‘Position’, [100, 100, 1000, 400]); % [left, bottom, width, height]
subplot(1, 2, 1);
u4 = pearscdf(samples4, mu4, sigma4, skew4, kurt4);
histogram(u4)
title(‘F(X) for Pearson 4’)
subplot(1, 2, 2);
u6 = pearscdf(samples6, mu6, sigma6, skew6, kurt6);
histogram(u6)
title(‘F(X) for Pearson 6’)
sgtitle(‘Test 2: Comparison between Pearson 4 and 6’);
%% Conclusion
%We get the expected results using the Pearson 6, but we cannot say the
%same for the Pearson 4. Why? We are having some trouble using the Pearson 4 implementation of the functions pearsrnd, pearspdf and pearscdf.
We think that pearsrnd does not generate samples from the distribution defined in pearspdf. In particular, we’ve found that pearsrnd over generates observations in the tails of the distribution.
In order to see this, we’ve implemented two simple tests:
1. We’ve compared the PDF of the Pearson 4 distribution (using pearspdf) to the PDF obtained from a simulation using pearsrnd, but we’ve found that the two are very different (even with a very long sample). This problem doesn’t happen for other distributions. In particular, we’ve implemented the same test with the Pearson 6, and the results are satisfactory.
2. In addition, to test if the generatated sample is compatible with its CDF, we’ve applied the function pearscdf to the generated sample. We should have got a uniform distribution, because if X is a random variable and F its CDF, then F(X) is uniform in [0,1]. This is indeed what we’ve got with the Pearson 6, as expected, but not what we’ve got using the Pearson 4.
We’ve conducted a similar experiment using Mathematica, and we get the correct result.
We’ve attached the code we’ve used.
Any idea why we’re getting this result?
Thank you very much.
%% Seed
rng(123)
%% Parameters
%Type IV
mu4 = 5;
sigma4 = 1;
skew4 = 1;
kurt4 = 10;
% Check the distribution type
[ign, type4] = pearsrnd(mu4, sigma4, skew4, kurt4, 1);
disp("This Pearson is of type " + type4)
% Type VI
mu6 = 2;
sigma6 = 1;
skew6 = 2;
kurt6 = 10;
% Check the distribution type
[ign, type6] = pearsrnd(mu6, sigma6, skew6, kurt6, 1);
disp("This Pearson is of type " + type6)
%% Simulate n observations according to both Pearson distributions defined above
n = 100000;
samples4 = pearsrnd(mu4, sigma4, skew4, kurt4, 1, n);
samples6 = pearsrnd(mu6, sigma6, skew6, kurt6, 1, n);
%% First test: we compare the simulated pdf (i.e. histogram of the sample) to the closed form PDF
pdf4 = @(x) pearspdf(x, mu4, sigma4, skew4, kurt4);
pdf6 = @(x) pearspdf(x, mu6, sigma6, skew6, kurt6);
x_ = linspace(-10, 10, 10000);
y4 = pdf4(x_);
y6 = pdf6(x_);
figure(‘Position’, [100, 100, 1000, 400]); % [left, bottom, width, height]
subplot(1, 2, 1);
plot(x_, y4, Color=’red’, LineWidth=2)
title(‘Simulated and closed form PDF for Pearson 4’)
hold on
histogram(samples4, 1000, ‘Normalization’, ‘pdf’, ‘FaceColor’, ‘blue’)
hold off
subplot(1, 2, 2);
plot(x_, y6, Color=’red’, LineWidth=2)
title(‘Simulated and closed form PDF for Pearson 6’)
hold on
histogram(samples6, 1000, ‘Normalization’, ‘pdf’, ‘FaceColor’, ‘blue’)
hold off
sgtitle(‘Test 1: Comparison between Pearson 4 and 6’);
%% Second test: Let X be a random variable and F its CDF, then F(X) is uniform in [0,1].
% We apply the Pearson CDF to the simulated observations and plot its
% histogram. We should obtain something resembling a uniform distribution.
figure(‘Position’, [100, 100, 1000, 400]); % [left, bottom, width, height]
subplot(1, 2, 1);
u4 = pearscdf(samples4, mu4, sigma4, skew4, kurt4);
histogram(u4)
title(‘F(X) for Pearson 4’)
subplot(1, 2, 2);
u6 = pearscdf(samples6, mu6, sigma6, skew6, kurt6);
histogram(u6)
title(‘F(X) for Pearson 6’)
sgtitle(‘Test 2: Comparison between Pearson 4 and 6’);
%% Conclusion
%We get the expected results using the Pearson 6, but we cannot say the
%same for the Pearson 4. Why? pearson, distribution, statistics, random number generator, type iv MATLAB Answers — New Questions