Tag Archives: matlab
Fit Multiple gaussian curve on data with flat tops
How to fit double gaussian curve for this data set which is flat at some domains?How to fit double gaussian curve for this data set which is flat at some domains? How to fit double gaussian curve for this data set which is flat at some domains? double gaussian fit for data with hat MATLAB Answers — New Questions
Generating Multivariate Polynomial Coeffients with known Constants
I am extremely new to MatLab and am having a hard time trying to generate Coefficients from this equation:
t= (A * a) + (B * s) + (C * s * a)+ (D * s^2) + (E * s^2 * a) + (F)
I have the data for t,s,a.
Trying to find (A,B,C,D,E,F)
I can remove the Coefficient (F) if need be, being it is just an offset, and I have (t).
I could post what I have tried, but I usually dont save it because I am not getting close.
I do have Curve Fitting, Statistics, and Optimization Toolboxes thinking it would help.
I have also tried polyfit and polyfitn.
Also, if this has been answered a hundred times, what would best describe that equation for searching?I am extremely new to MatLab and am having a hard time trying to generate Coefficients from this equation:
t= (A * a) + (B * s) + (C * s * a)+ (D * s^2) + (E * s^2 * a) + (F)
I have the data for t,s,a.
Trying to find (A,B,C,D,E,F)
I can remove the Coefficient (F) if need be, being it is just an offset, and I have (t).
I could post what I have tried, but I usually dont save it because I am not getting close.
I do have Curve Fitting, Statistics, and Optimization Toolboxes thinking it would help.
I have also tried polyfit and polyfitn.
Also, if this has been answered a hundred times, what would best describe that equation for searching? I am extremely new to MatLab and am having a hard time trying to generate Coefficients from this equation:
t= (A * a) + (B * s) + (C * s * a)+ (D * s^2) + (E * s^2 * a) + (F)
I have the data for t,s,a.
Trying to find (A,B,C,D,E,F)
I can remove the Coefficient (F) if need be, being it is just an offset, and I have (t).
I could post what I have tried, but I usually dont save it because I am not getting close.
I do have Curve Fitting, Statistics, and Optimization Toolboxes thinking it would help.
I have also tried polyfit and polyfitn.
Also, if this has been answered a hundred times, what would best describe that equation for searching? polyfit, polyfitn, polynomial, quadratic, multivariate, solve, multivariate polynomial, coefficient MATLAB Answers — New Questions
I want to make a bar graph for this data from a csv file that has multiple information in 1 column (A) how do I make this graph
Post Content Post Content bar graph, no hardcode MATLAB Answers — New Questions
Code not working on new laptop
Hello,
I have several scripts using EEGlab and one of its pluggin (mffimport). The scripts work well on other mac laptops (I’ve tried 3), but not on my new laptop (Macbookpro sonoma nov 2023). Any idea why?
I have changed the paths, dowloaded the necessarry toolboxes.
I have contacted EEGlab support who told me it’s a matlab problem and I have contacted Matlab support who told me it is a code problem, not a software problem, but my code works well on other laptops…
THank you in advance for your help.Hello,
I have several scripts using EEGlab and one of its pluggin (mffimport). The scripts work well on other mac laptops (I’ve tried 3), but not on my new laptop (Macbookpro sonoma nov 2023). Any idea why?
I have changed the paths, dowloaded the necessarry toolboxes.
I have contacted EEGlab support who told me it’s a matlab problem and I have contacted Matlab support who told me it is a code problem, not a software problem, but my code works well on other laptops…
THank you in advance for your help. Hello,
I have several scripts using EEGlab and one of its pluggin (mffimport). The scripts work well on other mac laptops (I’ve tried 3), but not on my new laptop (Macbookpro sonoma nov 2023). Any idea why?
I have changed the paths, dowloaded the necessarry toolboxes.
I have contacted EEGlab support who told me it’s a matlab problem and I have contacted Matlab support who told me it is a code problem, not a software problem, but my code works well on other laptops…
THank you in advance for your help. sonoma, eeglab, mffimport, matlab code MATLAB Answers — New Questions
How to speed up our code to be implemented on GPU
Hello, I have previously created my MEX file of my code to speed up its implementation speed on GPU. Fortunately, it got faster by 5 times, and hopefully, I want to know if there is way to implement it with higher speed. Here is my code:
function BPmimo2C(Efield) %#codegen
coder.gpu.kernelfun;
image = complex(zeros(17,54,54));
%% creating kaiser window
numT = 16;
numR= 16;
f = 10e9:0.5e9:20e9;
numF = numel(f);
w = ones(numel(f),1);
viq = repmat(w.’, [1,numT*numR]);
c = physconst(‘LightSpeed’);
%% grid points
xf = (-8:0.3:8)*0.01;
yf = (-8:0.3:8)*0.01;
[uf , vf] = meshgrid(xf,yf);
x1f = uf(:);
y1f = vf(:);
%% initialization
ArrRadius = 30;
TX = [ArrRadius.*cosd((360/15)*(0:14))*0.01 0];
TY = [ArrRadius.*sind((360/15)*(0:14))*0.01 0];
K = 2*pi*f/c;
z = 0.36:0.003:0.41;
% z = 0.4;
for dep = 1:numel(z)
%% making the matrix of <transmitter-grid point> distance
XYPos = [TX.’ TY.’ ones(size(TX,2),1)*(z(dep))];
UVPos = [x1f(:), y1f(:), zeros(size(y1f(:),1),1)];
dtXYUV = pdist2( XYPos, UVPos);
dtXYUV2 = zeros(numR,numel(x1f(:)));
expTerm1 = bsxfun(@times,dtXYUV(:)’ , K’);
expT1 = reshape(expTerm1,[numel(K),numel(TX),numel(x1f)]);
expT2 = zeros(numel(K),numR,numel(x1f),numel(TX));
for i = 1:numel(TX)
expT2(:,:,:,i) = repmat(expT1(:,i,:),[1 numR 1]);
dtXYUV2(:,:,i) = repmat(dtXYUV(i,:),[numR,1]);
end
expT = permute(reshape(permute(expT2,[1 3 2 4]),[numel(K),numel(x1f),numR*numel(TX)]),[1 3 2]);
%% making the matrix of <reciever-grid point> distance
XYPos = [real(Efield(1:numR,2,1)) , real(Efield(1:numR,3,1)), ones(numR,1)*(z(dep))];
UVPos = [x1f(:), y1f(:), zeros(size(y1f(:),1),1)];
dXYUV = pdist2( XYPos, UVPos);
expTerm1 = bsxfun(@times,dXYUV(:)’ , K’);
expR = repmat(reshape(expTerm1,[numel(K),numR,numel(x1f)]),[1 numel(TX) 1]);
%% making the exponentail term
EXP = exp(1i*(expT + expR));
EXP2 = reshape(EXP,[numel(K)*numel(TX)*numR,numel(x1f)]);
Efield2 = reshape(permute(Efield(1:numT*numR,:,:),[3 1 2]),[numel(f)*numT*numR,6]);
image2 = reshape(((viq.’).*Efield2(:,6)).’*EXP2,[sqrt(numel(x1f)),sqrt(numel(x1f))]);
%% gahter to change matrix from GPU-array to normal array
image(dep,:,:) = image2;
end
image = abs(image);
uf = repmat(reshape(uf,[1,numel(xf),numel(yf)]),[numel(z) 1 1]);
vf = repmat(reshape(vf,[1,numel(xf),numel(yf)]),[numel(z) 1 1]);
hf = uf;
for j = 1:numel(z)
hf(j,:,:) = z(j);
end
figure(1);
er = squeeze((image(13,:,:)));
h = surf(squeeze(uf(1,:,:)),squeeze(vf(1,:,:)),er);
colormap(jet);
set(h,’LineStyle’,’none’);
view(2);
end
In addition to speed, sometimes it encounters with "out of memory" error, which is due to huge size of some arrays. I can implement it using multiple nested "for"loops, however, I understood it’d be faster on CPU if I use MATLAB’s matrix multipication capability; Therefore, I preferred matrix-based code rather than multiple nested "for" loops.
Any advice, whether it would be general or specific, would be appreciated.
Thank youHello, I have previously created my MEX file of my code to speed up its implementation speed on GPU. Fortunately, it got faster by 5 times, and hopefully, I want to know if there is way to implement it with higher speed. Here is my code:
function BPmimo2C(Efield) %#codegen
coder.gpu.kernelfun;
image = complex(zeros(17,54,54));
%% creating kaiser window
numT = 16;
numR= 16;
f = 10e9:0.5e9:20e9;
numF = numel(f);
w = ones(numel(f),1);
viq = repmat(w.’, [1,numT*numR]);
c = physconst(‘LightSpeed’);
%% grid points
xf = (-8:0.3:8)*0.01;
yf = (-8:0.3:8)*0.01;
[uf , vf] = meshgrid(xf,yf);
x1f = uf(:);
y1f = vf(:);
%% initialization
ArrRadius = 30;
TX = [ArrRadius.*cosd((360/15)*(0:14))*0.01 0];
TY = [ArrRadius.*sind((360/15)*(0:14))*0.01 0];
K = 2*pi*f/c;
z = 0.36:0.003:0.41;
% z = 0.4;
for dep = 1:numel(z)
%% making the matrix of <transmitter-grid point> distance
XYPos = [TX.’ TY.’ ones(size(TX,2),1)*(z(dep))];
UVPos = [x1f(:), y1f(:), zeros(size(y1f(:),1),1)];
dtXYUV = pdist2( XYPos, UVPos);
dtXYUV2 = zeros(numR,numel(x1f(:)));
expTerm1 = bsxfun(@times,dtXYUV(:)’ , K’);
expT1 = reshape(expTerm1,[numel(K),numel(TX),numel(x1f)]);
expT2 = zeros(numel(K),numR,numel(x1f),numel(TX));
for i = 1:numel(TX)
expT2(:,:,:,i) = repmat(expT1(:,i,:),[1 numR 1]);
dtXYUV2(:,:,i) = repmat(dtXYUV(i,:),[numR,1]);
end
expT = permute(reshape(permute(expT2,[1 3 2 4]),[numel(K),numel(x1f),numR*numel(TX)]),[1 3 2]);
%% making the matrix of <reciever-grid point> distance
XYPos = [real(Efield(1:numR,2,1)) , real(Efield(1:numR,3,1)), ones(numR,1)*(z(dep))];
UVPos = [x1f(:), y1f(:), zeros(size(y1f(:),1),1)];
dXYUV = pdist2( XYPos, UVPos);
expTerm1 = bsxfun(@times,dXYUV(:)’ , K’);
expR = repmat(reshape(expTerm1,[numel(K),numR,numel(x1f)]),[1 numel(TX) 1]);
%% making the exponentail term
EXP = exp(1i*(expT + expR));
EXP2 = reshape(EXP,[numel(K)*numel(TX)*numR,numel(x1f)]);
Efield2 = reshape(permute(Efield(1:numT*numR,:,:),[3 1 2]),[numel(f)*numT*numR,6]);
image2 = reshape(((viq.’).*Efield2(:,6)).’*EXP2,[sqrt(numel(x1f)),sqrt(numel(x1f))]);
%% gahter to change matrix from GPU-array to normal array
image(dep,:,:) = image2;
end
image = abs(image);
uf = repmat(reshape(uf,[1,numel(xf),numel(yf)]),[numel(z) 1 1]);
vf = repmat(reshape(vf,[1,numel(xf),numel(yf)]),[numel(z) 1 1]);
hf = uf;
for j = 1:numel(z)
hf(j,:,:) = z(j);
end
figure(1);
er = squeeze((image(13,:,:)));
h = surf(squeeze(uf(1,:,:)),squeeze(vf(1,:,:)),er);
colormap(jet);
set(h,’LineStyle’,’none’);
view(2);
end
In addition to speed, sometimes it encounters with "out of memory" error, which is due to huge size of some arrays. I can implement it using multiple nested "for"loops, however, I understood it’d be faster on CPU if I use MATLAB’s matrix multipication capability; Therefore, I preferred matrix-based code rather than multiple nested "for" loops.
Any advice, whether it would be general or specific, would be appreciated.
Thank you Hello, I have previously created my MEX file of my code to speed up its implementation speed on GPU. Fortunately, it got faster by 5 times, and hopefully, I want to know if there is way to implement it with higher speed. Here is my code:
function BPmimo2C(Efield) %#codegen
coder.gpu.kernelfun;
image = complex(zeros(17,54,54));
%% creating kaiser window
numT = 16;
numR= 16;
f = 10e9:0.5e9:20e9;
numF = numel(f);
w = ones(numel(f),1);
viq = repmat(w.’, [1,numT*numR]);
c = physconst(‘LightSpeed’);
%% grid points
xf = (-8:0.3:8)*0.01;
yf = (-8:0.3:8)*0.01;
[uf , vf] = meshgrid(xf,yf);
x1f = uf(:);
y1f = vf(:);
%% initialization
ArrRadius = 30;
TX = [ArrRadius.*cosd((360/15)*(0:14))*0.01 0];
TY = [ArrRadius.*sind((360/15)*(0:14))*0.01 0];
K = 2*pi*f/c;
z = 0.36:0.003:0.41;
% z = 0.4;
for dep = 1:numel(z)
%% making the matrix of <transmitter-grid point> distance
XYPos = [TX.’ TY.’ ones(size(TX,2),1)*(z(dep))];
UVPos = [x1f(:), y1f(:), zeros(size(y1f(:),1),1)];
dtXYUV = pdist2( XYPos, UVPos);
dtXYUV2 = zeros(numR,numel(x1f(:)));
expTerm1 = bsxfun(@times,dtXYUV(:)’ , K’);
expT1 = reshape(expTerm1,[numel(K),numel(TX),numel(x1f)]);
expT2 = zeros(numel(K),numR,numel(x1f),numel(TX));
for i = 1:numel(TX)
expT2(:,:,:,i) = repmat(expT1(:,i,:),[1 numR 1]);
dtXYUV2(:,:,i) = repmat(dtXYUV(i,:),[numR,1]);
end
expT = permute(reshape(permute(expT2,[1 3 2 4]),[numel(K),numel(x1f),numR*numel(TX)]),[1 3 2]);
%% making the matrix of <reciever-grid point> distance
XYPos = [real(Efield(1:numR,2,1)) , real(Efield(1:numR,3,1)), ones(numR,1)*(z(dep))];
UVPos = [x1f(:), y1f(:), zeros(size(y1f(:),1),1)];
dXYUV = pdist2( XYPos, UVPos);
expTerm1 = bsxfun(@times,dXYUV(:)’ , K’);
expR = repmat(reshape(expTerm1,[numel(K),numR,numel(x1f)]),[1 numel(TX) 1]);
%% making the exponentail term
EXP = exp(1i*(expT + expR));
EXP2 = reshape(EXP,[numel(K)*numel(TX)*numR,numel(x1f)]);
Efield2 = reshape(permute(Efield(1:numT*numR,:,:),[3 1 2]),[numel(f)*numT*numR,6]);
image2 = reshape(((viq.’).*Efield2(:,6)).’*EXP2,[sqrt(numel(x1f)),sqrt(numel(x1f))]);
%% gahter to change matrix from GPU-array to normal array
image(dep,:,:) = image2;
end
image = abs(image);
uf = repmat(reshape(uf,[1,numel(xf),numel(yf)]),[numel(z) 1 1]);
vf = repmat(reshape(vf,[1,numel(xf),numel(yf)]),[numel(z) 1 1]);
hf = uf;
for j = 1:numel(z)
hf(j,:,:) = z(j);
end
figure(1);
er = squeeze((image(13,:,:)));
h = surf(squeeze(uf(1,:,:)),squeeze(vf(1,:,:)),er);
colormap(jet);
set(h,’LineStyle’,’none’);
view(2);
end
In addition to speed, sometimes it encounters with "out of memory" error, which is due to huge size of some arrays. I can implement it using multiple nested "for"loops, however, I understood it’d be faster on CPU if I use MATLAB’s matrix multipication capability; Therefore, I preferred matrix-based code rather than multiple nested "for" loops.
Any advice, whether it would be general or specific, would be appreciated.
Thank you gpu coder, matlab, gpu, speed, mex MATLAB Answers — New Questions
Where is the polyIntersect.m function in R2024 and how do I load it ?
I have updated my R2022 license and can’t locate the polyIintersect.m function and load it ? I need the function
for an old programI have updated my R2022 license and can’t locate the polyIintersect.m function and load it ? I need the function
for an old program I have updated my R2022 license and can’t locate the polyIintersect.m function and load it ? I need the function
for an old program polyintersect.m MATLAB Answers — New Questions
“Nonlinear Transformer” model usage
Hi I am trying to use Nonlinear Transformer function. The web document indicates following parameters, which makes sense to me.
On the other hand, when open the model setting, the parameters are different from above. What am I missing. Thanks.Hi I am trying to use Nonlinear Transformer function. The web document indicates following parameters, which makes sense to me.
On the other hand, when open the model setting, the parameters are different from above. What am I missing. Thanks. Hi I am trying to use Nonlinear Transformer function. The web document indicates following parameters, which makes sense to me.
On the other hand, when open the model setting, the parameters are different from above. What am I missing. Thanks. nonlinear transformer MATLAB Answers — New Questions
How do I extract TEC variability from GPS data Using MATLAB
hello
need scripts to extract TEC variability from GPS data Using MATLAB,
tkuhello
need scripts to extract TEC variability from GPS data Using MATLAB,
tku hello
need scripts to extract TEC variability from GPS data Using MATLAB,
tku tec, gps, matlab MATLAB Answers — New Questions
Add a toolbox
I need to add 2 toolboxes to Matlab, when I use the "add path" function it adds itself naturally and I "save" the current paths but the problem is once I log off Matlab it restores to the paths before adding these two toolboxes !!
Meanwhile if I said I will add them each time, I have no problem with that but it returns a message calling "out of memory" when trying to use the "sift" command.
I appreciate if you can help me. Thank youI need to add 2 toolboxes to Matlab, when I use the "add path" function it adds itself naturally and I "save" the current paths but the problem is once I log off Matlab it restores to the paths before adding these two toolboxes !!
Meanwhile if I said I will add them each time, I have no problem with that but it returns a message calling "out of memory" when trying to use the "sift" command.
I appreciate if you can help me. Thank you I need to add 2 toolboxes to Matlab, when I use the "add path" function it adds itself naturally and I "save" the current paths but the problem is once I log off Matlab it restores to the paths before adding these two toolboxes !!
Meanwhile if I said I will add them each time, I have no problem with that but it returns a message calling "out of memory" when trying to use the "sift" command.
I appreciate if you can help me. Thank you out of memory, add toolbox MATLAB Answers — New Questions
Cannot find the attached segmentation mask from the supporting file of Medical Image-Based Finite Element Analysis of Spine documentation
Hello everyone,
May I ask for some assitances from who have ever tried to reproduce the example from MATLAB documentation? I have tried to reproduce the Medical Image-Based Finite Element Analysis of Spine from this link : https://www.mathworks.com/help/medical-imaging/ug/Medical-Image-Based-Finite-Element-Analysis-of-Spine.html#MedicalImageBasedFiniteElementAnalysisOfSpineExample-2 .
When I have downloaded the example with the provided code below.
zipFile = matlab.internal.examples.downloadSupportFile("medical","MedicalVolumeDICOMData.zip");
I cannot find the segmentation mask as described in the documentation.
Are there anyone who have ever experienced the issues about reproducing the example from MATLAB documatation? If yes, how do you deal with the issue? Really appreciated, every supportive comments.Hello everyone,
May I ask for some assitances from who have ever tried to reproduce the example from MATLAB documentation? I have tried to reproduce the Medical Image-Based Finite Element Analysis of Spine from this link : https://www.mathworks.com/help/medical-imaging/ug/Medical-Image-Based-Finite-Element-Analysis-of-Spine.html#MedicalImageBasedFiniteElementAnalysisOfSpineExample-2 .
When I have downloaded the example with the provided code below.
zipFile = matlab.internal.examples.downloadSupportFile("medical","MedicalVolumeDICOMData.zip");
I cannot find the segmentation mask as described in the documentation.
Are there anyone who have ever experienced the issues about reproducing the example from MATLAB documatation? If yes, how do you deal with the issue? Really appreciated, every supportive comments. Hello everyone,
May I ask for some assitances from who have ever tried to reproduce the example from MATLAB documentation? I have tried to reproduce the Medical Image-Based Finite Element Analysis of Spine from this link : https://www.mathworks.com/help/medical-imaging/ug/Medical-Image-Based-Finite-Element-Analysis-of-Spine.html#MedicalImageBasedFiniteElementAnalysisOfSpineExample-2 .
When I have downloaded the example with the provided code below.
zipFile = matlab.internal.examples.downloadSupportFile("medical","MedicalVolumeDICOMData.zip");
I cannot find the segmentation mask as described in the documentation.
Are there anyone who have ever experienced the issues about reproducing the example from MATLAB documatation? If yes, how do you deal with the issue? Really appreciated, every supportive comments. matlab documentation, finite element analysis MATLAB Answers — New Questions
Function is throwing error when calling it in different script
I have a function, attached, that I am calling in different script. Everytime I call it I get the error
"Local function name must be different from the script name"
I was under the impression both the script and function must have the same name? Atleast how i have my other functions working. Nonetheless, even when I resave it with a different name I cant get it to workI have a function, attached, that I am calling in different script. Everytime I call it I get the error
"Local function name must be different from the script name"
I was under the impression both the script and function must have the same name? Atleast how i have my other functions working. Nonetheless, even when I resave it with a different name I cant get it to work I have a function, attached, that I am calling in different script. Everytime I call it I get the error
"Local function name must be different from the script name"
I was under the impression both the script and function must have the same name? Atleast how i have my other functions working. Nonetheless, even when I resave it with a different name I cant get it to work function MATLAB Answers — New Questions
Face vertices of a 3D voronoi cell
I have generated a 3D Voronoi tessellations from a set of random seed points. Now, how can I determine the number of faces and the vertices that form each face for each 3D Voronoi cell?
P = rand(10, 3); % Example: 10 random points in 3D
[V, C] = voronoin(P);
C{i} gives me the indices of all the vertices that form the cell but I need information for the faces.
Your help and sopport is very much appreciated.
Thank you.I have generated a 3D Voronoi tessellations from a set of random seed points. Now, how can I determine the number of faces and the vertices that form each face for each 3D Voronoi cell?
P = rand(10, 3); % Example: 10 random points in 3D
[V, C] = voronoin(P);
C{i} gives me the indices of all the vertices that form the cell but I need information for the faces.
Your help and sopport is very much appreciated.
Thank you. I have generated a 3D Voronoi tessellations from a set of random seed points. Now, how can I determine the number of faces and the vertices that form each face for each 3D Voronoi cell?
P = rand(10, 3); % Example: 10 random points in 3D
[V, C] = voronoin(P);
C{i} gives me the indices of all the vertices that form the cell but I need information for the faces.
Your help and sopport is very much appreciated.
Thank you. voronoi, 3d, vertices, faces, edges, polygon MATLAB Answers — New Questions
App not calling EditFieldValueChanging(app, event) callback when initial value is empty string.
I have a Sudoku app with text boxes (numerical, but it doesn’t seem to matter).
I want to control the user input with a ValueChanging callback. These callbacks are working once there’s already a value in them, but the callbacks aren’t called as the value changes from " " to "5555". I tried using a while loop to make them constantly observe the value of the box, but again it only works if the initial value isn’t an empty string…
I don’t know much about events, so if there is a way to force the active textbox to call the ValueChanging callback everytime a key is pressed, I think that is a workable solution.
Here is the callback code as it stands now:
function R11ValueChanging(app, event)
changingValue = event.Value;
while (changingValue ~= "" && changingValue ~= "1" && changingValue ~= "2" && changingValue ~= "3" && changingValue ~= "4" …
&& changingValue ~= "5" && changingValue ~= "6" && changingValue ~= "7" && changingValue ~= "8" && changingValue ~= "9")
app.R11.Value = "";
changingValue = "";
end
end
As I mentioned before, this code does dynamically clear the textbox if something invalid is typed, so in that sense it works, but it just doesn’t seem to recognize the ValueChanging event is occurring when the value begins as an empty string.
Edit: I just double-checked something I said, and I found out something weirder. The callback function is actually called. In debug mode, the invalid character gets deleted. But when I don’t have any breakpoints, the invalid character stays there…. so now I definitely need help with this…
Here is a video of what’s going on: https://youtu.be/SYnlw5GbDAQI have a Sudoku app with text boxes (numerical, but it doesn’t seem to matter).
I want to control the user input with a ValueChanging callback. These callbacks are working once there’s already a value in them, but the callbacks aren’t called as the value changes from " " to "5555". I tried using a while loop to make them constantly observe the value of the box, but again it only works if the initial value isn’t an empty string…
I don’t know much about events, so if there is a way to force the active textbox to call the ValueChanging callback everytime a key is pressed, I think that is a workable solution.
Here is the callback code as it stands now:
function R11ValueChanging(app, event)
changingValue = event.Value;
while (changingValue ~= "" && changingValue ~= "1" && changingValue ~= "2" && changingValue ~= "3" && changingValue ~= "4" …
&& changingValue ~= "5" && changingValue ~= "6" && changingValue ~= "7" && changingValue ~= "8" && changingValue ~= "9")
app.R11.Value = "";
changingValue = "";
end
end
As I mentioned before, this code does dynamically clear the textbox if something invalid is typed, so in that sense it works, but it just doesn’t seem to recognize the ValueChanging event is occurring when the value begins as an empty string.
Edit: I just double-checked something I said, and I found out something weirder. The callback function is actually called. In debug mode, the invalid character gets deleted. But when I don’t have any breakpoints, the invalid character stays there…. so now I definitely need help with this…
Here is a video of what’s going on: https://youtu.be/SYnlw5GbDAQ I have a Sudoku app with text boxes (numerical, but it doesn’t seem to matter).
I want to control the user input with a ValueChanging callback. These callbacks are working once there’s already a value in them, but the callbacks aren’t called as the value changes from " " to "5555". I tried using a while loop to make them constantly observe the value of the box, but again it only works if the initial value isn’t an empty string…
I don’t know much about events, so if there is a way to force the active textbox to call the ValueChanging callback everytime a key is pressed, I think that is a workable solution.
Here is the callback code as it stands now:
function R11ValueChanging(app, event)
changingValue = event.Value;
while (changingValue ~= "" && changingValue ~= "1" && changingValue ~= "2" && changingValue ~= "3" && changingValue ~= "4" …
&& changingValue ~= "5" && changingValue ~= "6" && changingValue ~= "7" && changingValue ~= "8" && changingValue ~= "9")
app.R11.Value = "";
changingValue = "";
end
end
As I mentioned before, this code does dynamically clear the textbox if something invalid is typed, so in that sense it works, but it just doesn’t seem to recognize the ValueChanging event is occurring when the value begins as an empty string.
Edit: I just double-checked something I said, and I found out something weirder. The callback function is actually called. In debug mode, the invalid character gets deleted. But when I don’t have any breakpoints, the invalid character stays there…. so now I definitely need help with this…
Here is a video of what’s going on: https://youtu.be/SYnlw5GbDAQ events, matlab, app designer MATLAB Answers — New Questions
Evaluate advanced integral numerically
Hi
I am trying to evaluate the following integral in MATLAB: http://www.scribd.com/doc/100400549/mwe
However I haven’t had any success, nor in a competing software (I’m not sure I’m allowed to mention its name). Do you guys know if it is even possible to evaluate such an integral in MATLAB? I have spent so many hours on this by now..
I would be very happy to get some feedback.
Best,
Niles.Hi
I am trying to evaluate the following integral in MATLAB: http://www.scribd.com/doc/100400549/mwe
However I haven’t had any success, nor in a competing software (I’m not sure I’m allowed to mention its name). Do you guys know if it is even possible to evaluate such an integral in MATLAB? I have spent so many hours on this by now..
I would be very happy to get some feedback.
Best,
Niles. Hi
I am trying to evaluate the following integral in MATLAB: http://www.scribd.com/doc/100400549/mwe
However I haven’t had any success, nor in a competing software (I’m not sure I’m allowed to mention its name). Do you guys know if it is even possible to evaluate such an integral in MATLAB? I have spent so many hours on this by now..
I would be very happy to get some feedback.
Best,
Niles. numerical integration, difficult MATLAB Answers — New Questions
Not able to interpolate the corners of figure using ScattteredInterpolation function
I have a data which is scattered and I want to regularise the data using ScatterredInterpolation function. The point cloud, I’m working is a square tube(rawfigure attached). When I try to regularise the data using ScatterredInterpolation, I’m getting a figure something like this (transformedfig attached), which has large undulations at the corners of the tube (it is supposed to be smooth edge like in the ‘rawfigure’). Please let me know what could be the problem and solution.
code which I’m using is,
CTP = [R theta Y]; %.mat file attached
O_x = 1.5940;
O_z = -66.2657;
max_y = max(Y);
min_y = min(Y);
F = scatteredInterpolant(CTP(:,2), CTP(:,3), CTP(:,1)); %Interpolation funcntion for "R"
Xq = 0:4*pi()/(180):2*pi(); %mesh in x direction
Yq = min_y:4:max_y; %mesh in y direction
[XQ, YQ] = meshgrid(Xq, Yq);%meshgrid with the predefined size
ZQ = F(XQ, YQ); %"R" values for the meshgrid
[m n] = size(XQ);
for i = 1:n:n*(m)
C([i:i+(n-1)],[1:3]) = [XQ(((n-1)+i)/n,:)’ YQ(((n-1)+i)/n,:)’ ZQ(((n-1)+i)/n,:)’];
end
X1 = -C(:,3).*cos(C(:,1))+O_x; %Reverse transform to cartesian coordinates
Z1 = C(:,3).*sin(C(:,1)) + O_z; %Reverse transform to cartesian coordinates
Y1 = C(:,2); %Reverse transform
P1 = [X1 Y1 Z1]; %arranging cartesian coordinates
Pc = pointCloud(P1);
pcshow(Pc)
Thanks,I have a data which is scattered and I want to regularise the data using ScatterredInterpolation function. The point cloud, I’m working is a square tube(rawfigure attached). When I try to regularise the data using ScatterredInterpolation, I’m getting a figure something like this (transformedfig attached), which has large undulations at the corners of the tube (it is supposed to be smooth edge like in the ‘rawfigure’). Please let me know what could be the problem and solution.
code which I’m using is,
CTP = [R theta Y]; %.mat file attached
O_x = 1.5940;
O_z = -66.2657;
max_y = max(Y);
min_y = min(Y);
F = scatteredInterpolant(CTP(:,2), CTP(:,3), CTP(:,1)); %Interpolation funcntion for "R"
Xq = 0:4*pi()/(180):2*pi(); %mesh in x direction
Yq = min_y:4:max_y; %mesh in y direction
[XQ, YQ] = meshgrid(Xq, Yq);%meshgrid with the predefined size
ZQ = F(XQ, YQ); %"R" values for the meshgrid
[m n] = size(XQ);
for i = 1:n:n*(m)
C([i:i+(n-1)],[1:3]) = [XQ(((n-1)+i)/n,:)’ YQ(((n-1)+i)/n,:)’ ZQ(((n-1)+i)/n,:)’];
end
X1 = -C(:,3).*cos(C(:,1))+O_x; %Reverse transform to cartesian coordinates
Z1 = C(:,3).*sin(C(:,1)) + O_z; %Reverse transform to cartesian coordinates
Y1 = C(:,2); %Reverse transform
P1 = [X1 Y1 Z1]; %arranging cartesian coordinates
Pc = pointCloud(P1);
pcshow(Pc)
Thanks, I have a data which is scattered and I want to regularise the data using ScatterredInterpolation function. The point cloud, I’m working is a square tube(rawfigure attached). When I try to regularise the data using ScatterredInterpolation, I’m getting a figure something like this (transformedfig attached), which has large undulations at the corners of the tube (it is supposed to be smooth edge like in the ‘rawfigure’). Please let me know what could be the problem and solution.
code which I’m using is,
CTP = [R theta Y]; %.mat file attached
O_x = 1.5940;
O_z = -66.2657;
max_y = max(Y);
min_y = min(Y);
F = scatteredInterpolant(CTP(:,2), CTP(:,3), CTP(:,1)); %Interpolation funcntion for "R"
Xq = 0:4*pi()/(180):2*pi(); %mesh in x direction
Yq = min_y:4:max_y; %mesh in y direction
[XQ, YQ] = meshgrid(Xq, Yq);%meshgrid with the predefined size
ZQ = F(XQ, YQ); %"R" values for the meshgrid
[m n] = size(XQ);
for i = 1:n:n*(m)
C([i:i+(n-1)],[1:3]) = [XQ(((n-1)+i)/n,:)’ YQ(((n-1)+i)/n,:)’ ZQ(((n-1)+i)/n,:)’];
end
X1 = -C(:,3).*cos(C(:,1))+O_x; %Reverse transform to cartesian coordinates
Z1 = C(:,3).*sin(C(:,1)) + O_z; %Reverse transform to cartesian coordinates
Y1 = C(:,2); %Reverse transform
P1 = [X1 Y1 Z1]; %arranging cartesian coordinates
Pc = pointCloud(P1);
pcshow(Pc)
Thanks, scatteredinterpolation MATLAB Answers — New Questions
Find closest value in array
I have two vector(which are time stamps) like,
V N
1375471092848936 1375473384440853
1375473388165900 1375471277856598
1375471320476780 1375473388165900
1375473388947681 1375471322465961
1375473392527002 1375471335206288
……………… ………………
My goal is to find closest time in N with respect to V (i.e. find time in N which is nearly equal with V). My frame is W = 1e4, furthermore V should lies between N-W and N+W. So how do I get closest time through MATLAB? Any help would be appreciated.
ThanksI have two vector(which are time stamps) like,
V N
1375471092848936 1375473384440853
1375473388165900 1375471277856598
1375471320476780 1375473388165900
1375473388947681 1375471322465961
1375473392527002 1375471335206288
……………… ………………
My goal is to find closest time in N with respect to V (i.e. find time in N which is nearly equal with V). My frame is W = 1e4, furthermore V should lies between N-W and N+W. So how do I get closest time through MATLAB? Any help would be appreciated.
Thanks I have two vector(which are time stamps) like,
V N
1375471092848936 1375473384440853
1375473388165900 1375471277856598
1375471320476780 1375473388165900
1375473388947681 1375471322465961
1375473392527002 1375471335206288
……………… ………………
My goal is to find closest time in N with respect to V (i.e. find time in N which is nearly equal with V). My frame is W = 1e4, furthermore V should lies between N-W and N+W. So how do I get closest time through MATLAB? Any help would be appreciated.
Thanks vector, array, closest value MATLAB Answers — New Questions
Warning Msg: Trace to source might be incomplete because trace enters a loop
Hello everyone,
i´m having a Simulink Model which consists of custom library blocks. The connections between the blocks can be seen in the attached picture (BlockDiagramm.jpg ; highlighted trace).
During connecting the blocks, the Matlab Command Window gets filled with a lot of warning messages from same type:
"Warning: Trace to source might be incomplete because the trace enters a loop at output port 1 of …"
When I run the model, no warning or error message appears (-> Simulink is able to solve it and serves correct values).
So i´m wondering about the behaviour during building the model – why does Matlab send those warning messages before running the model and how to get rid of them? For signals in a loop I use the "Unit Delay"-Block.
Typing >> Simulink.BlockDiagram.getAlgebraicLoops(bdroot) << provides:
No algebraic loops were found.
ans =
0×0 AlgebraicLoop array with properties:
Model
Id
VariableBlockHandles
BlockHandles
IsArtificial
Typing >> w = warning(‘query’,’last’) << provides:
identifier: ‘Simulink:HiliteTool:LineTracingBusLoopWarning’
state: ‘on’
I know that i can turn the warning off using warning(‘off’,w.identifier) – but it would be nice to debug my model. And if there is not a problem with the model in general, I´d like to disable this warning constantly. It has to be said, that the warning does not appear on the diagnostic screen in Simulink, but in the Command Window in Matlab. Turning off "Edit-Time Errors and Warnings" in Simulink doesn´t help.
Thanks for your answers in advance.Hello everyone,
i´m having a Simulink Model which consists of custom library blocks. The connections between the blocks can be seen in the attached picture (BlockDiagramm.jpg ; highlighted trace).
During connecting the blocks, the Matlab Command Window gets filled with a lot of warning messages from same type:
"Warning: Trace to source might be incomplete because the trace enters a loop at output port 1 of …"
When I run the model, no warning or error message appears (-> Simulink is able to solve it and serves correct values).
So i´m wondering about the behaviour during building the model – why does Matlab send those warning messages before running the model and how to get rid of them? For signals in a loop I use the "Unit Delay"-Block.
Typing >> Simulink.BlockDiagram.getAlgebraicLoops(bdroot) << provides:
No algebraic loops were found.
ans =
0×0 AlgebraicLoop array with properties:
Model
Id
VariableBlockHandles
BlockHandles
IsArtificial
Typing >> w = warning(‘query’,’last’) << provides:
identifier: ‘Simulink:HiliteTool:LineTracingBusLoopWarning’
state: ‘on’
I know that i can turn the warning off using warning(‘off’,w.identifier) – but it would be nice to debug my model. And if there is not a problem with the model in general, I´d like to disable this warning constantly. It has to be said, that the warning does not appear on the diagnostic screen in Simulink, but in the Command Window in Matlab. Turning off "Edit-Time Errors and Warnings" in Simulink doesn´t help.
Thanks for your answers in advance. Hello everyone,
i´m having a Simulink Model which consists of custom library blocks. The connections between the blocks can be seen in the attached picture (BlockDiagramm.jpg ; highlighted trace).
During connecting the blocks, the Matlab Command Window gets filled with a lot of warning messages from same type:
"Warning: Trace to source might be incomplete because the trace enters a loop at output port 1 of …"
When I run the model, no warning or error message appears (-> Simulink is able to solve it and serves correct values).
So i´m wondering about the behaviour during building the model – why does Matlab send those warning messages before running the model and how to get rid of them? For signals in a loop I use the "Unit Delay"-Block.
Typing >> Simulink.BlockDiagram.getAlgebraicLoops(bdroot) << provides:
No algebraic loops were found.
ans =
0×0 AlgebraicLoop array with properties:
Model
Id
VariableBlockHandles
BlockHandles
IsArtificial
Typing >> w = warning(‘query’,’last’) << provides:
identifier: ‘Simulink:HiliteTool:LineTracingBusLoopWarning’
state: ‘on’
I know that i can turn the warning off using warning(‘off’,w.identifier) – but it would be nice to debug my model. And if there is not a problem with the model in general, I´d like to disable this warning constantly. It has to be said, that the warning does not appear on the diagnostic screen in Simulink, but in the Command Window in Matlab. Turning off "Edit-Time Errors and Warnings" in Simulink doesn´t help.
Thanks for your answers in advance. warning linetracing, busloop MATLAB Answers — New Questions
How To Throw Out First Frame in Equivalence Test in Test Case Manager
Due to some convergence stuff, I need to remove the first frame in the equivalence test in Test Case Manager, to make the signals match correctly. Is there a way to do that?Due to some convergence stuff, I need to remove the first frame in the equivalence test in Test Case Manager, to make the signals match correctly. Is there a way to do that? Due to some convergence stuff, I need to remove the first frame in the equivalence test in Test Case Manager, to make the signals match correctly. Is there a way to do that? simulink, testing, test case manager MATLAB Answers — New Questions
ginput occasionally not displaying cursor on app.UIFigure or UIAxes (App Designer)
Has anyone else had issues with the functionality of ginput with app designer created figures? On seemingly random occasions when ginput is called, the "mouse" pointer predictabily dissappears, but the crosshairs do not appear, leaving the user blind as to where they are on the figure. When this occurs, there appears to be no way to correct it other than to restart the application and losing all progress. The inputs DO still register when the user clicks on the figure though! There are also no errors when the callback is run and the line function run after with these inputs (shown below) will plot on the axes.
I have tried setting the handle visibility to ‘callback’ and specifying the current figure to try to "point" the function to the app figure, but this hasn’t prevented the issue.
For additional context, what I am doing is receiving user input of a range of X values on a 1D plot or 2D matrix, plotted on an app.UIAxes, and store the info in a cell array. The user must cycle through multiple plots/matrices and the app updates the values as they are changed. "r" is the index of the plot they are on, and "e" is the index of the selected input range. The user can add multiple "e"s (input ranges) through an add tool which also utilizes the ginput function.
I have used ginput in a number of ways to collect input on matrices/images as well, and frequently encounter this issue. I’m aware there is a separate selection tool on the axes object however I don’t know how to use it accordingly to programmatically recieve the values in a callback.
function EditPointsButtonPushed(app, event)
r = app.r;
e = app.e
assert(~verLessThan(‘Matlab’, ‘9.9’), ‘ginput not supported prior to Matlab r2020b.’)
fhv = app.UIFigure.HandleVisibility
app.UIFigure.HandleVisibility = ‘callback’
set(0, ‘CurrentFigure’, app.UIFigure)
[X1 ~] = ginput(2)
app.UIFigure.HandleVisibility = fhv;
line([X1(1) X1(1)],[Ymin max(app.Eventplots{r,e}(:,2))]); %1 needs to be axis min
line([X1(2) X1(2)],[Ymin max(app.Eventplots{r,e}(:,2))]);
app.Editpoints = round(X1)
end
I should also mention that the app is structured with a gridlayout, with panels that contain the axes. I thought that possibly ginput was occasionally being called onto the figure underneath these panels, however as others have mentioned in other questions, you cannot specify ginput onto objects/axes/etc and I cannot see the cursor when I move it between panels. I’m not sure what else to try, so any ideas would be greatly appreciated!!Has anyone else had issues with the functionality of ginput with app designer created figures? On seemingly random occasions when ginput is called, the "mouse" pointer predictabily dissappears, but the crosshairs do not appear, leaving the user blind as to where they are on the figure. When this occurs, there appears to be no way to correct it other than to restart the application and losing all progress. The inputs DO still register when the user clicks on the figure though! There are also no errors when the callback is run and the line function run after with these inputs (shown below) will plot on the axes.
I have tried setting the handle visibility to ‘callback’ and specifying the current figure to try to "point" the function to the app figure, but this hasn’t prevented the issue.
For additional context, what I am doing is receiving user input of a range of X values on a 1D plot or 2D matrix, plotted on an app.UIAxes, and store the info in a cell array. The user must cycle through multiple plots/matrices and the app updates the values as they are changed. "r" is the index of the plot they are on, and "e" is the index of the selected input range. The user can add multiple "e"s (input ranges) through an add tool which also utilizes the ginput function.
I have used ginput in a number of ways to collect input on matrices/images as well, and frequently encounter this issue. I’m aware there is a separate selection tool on the axes object however I don’t know how to use it accordingly to programmatically recieve the values in a callback.
function EditPointsButtonPushed(app, event)
r = app.r;
e = app.e
assert(~verLessThan(‘Matlab’, ‘9.9’), ‘ginput not supported prior to Matlab r2020b.’)
fhv = app.UIFigure.HandleVisibility
app.UIFigure.HandleVisibility = ‘callback’
set(0, ‘CurrentFigure’, app.UIFigure)
[X1 ~] = ginput(2)
app.UIFigure.HandleVisibility = fhv;
line([X1(1) X1(1)],[Ymin max(app.Eventplots{r,e}(:,2))]); %1 needs to be axis min
line([X1(2) X1(2)],[Ymin max(app.Eventplots{r,e}(:,2))]);
app.Editpoints = round(X1)
end
I should also mention that the app is structured with a gridlayout, with panels that contain the axes. I thought that possibly ginput was occasionally being called onto the figure underneath these panels, however as others have mentioned in other questions, you cannot specify ginput onto objects/axes/etc and I cannot see the cursor when I move it between panels. I’m not sure what else to try, so any ideas would be greatly appreciated!! Has anyone else had issues with the functionality of ginput with app designer created figures? On seemingly random occasions when ginput is called, the "mouse" pointer predictabily dissappears, but the crosshairs do not appear, leaving the user blind as to where they are on the figure. When this occurs, there appears to be no way to correct it other than to restart the application and losing all progress. The inputs DO still register when the user clicks on the figure though! There are also no errors when the callback is run and the line function run after with these inputs (shown below) will plot on the axes.
I have tried setting the handle visibility to ‘callback’ and specifying the current figure to try to "point" the function to the app figure, but this hasn’t prevented the issue.
For additional context, what I am doing is receiving user input of a range of X values on a 1D plot or 2D matrix, plotted on an app.UIAxes, and store the info in a cell array. The user must cycle through multiple plots/matrices and the app updates the values as they are changed. "r" is the index of the plot they are on, and "e" is the index of the selected input range. The user can add multiple "e"s (input ranges) through an add tool which also utilizes the ginput function.
I have used ginput in a number of ways to collect input on matrices/images as well, and frequently encounter this issue. I’m aware there is a separate selection tool on the axes object however I don’t know how to use it accordingly to programmatically recieve the values in a callback.
function EditPointsButtonPushed(app, event)
r = app.r;
e = app.e
assert(~verLessThan(‘Matlab’, ‘9.9’), ‘ginput not supported prior to Matlab r2020b.’)
fhv = app.UIFigure.HandleVisibility
app.UIFigure.HandleVisibility = ‘callback’
set(0, ‘CurrentFigure’, app.UIFigure)
[X1 ~] = ginput(2)
app.UIFigure.HandleVisibility = fhv;
line([X1(1) X1(1)],[Ymin max(app.Eventplots{r,e}(:,2))]); %1 needs to be axis min
line([X1(2) X1(2)],[Ymin max(app.Eventplots{r,e}(:,2))]);
app.Editpoints = round(X1)
end
I should also mention that the app is structured with a gridlayout, with panels that contain the axes. I thought that possibly ginput was occasionally being called onto the figure underneath these panels, however as others have mentioned in other questions, you cannot specify ginput onto objects/axes/etc and I cannot see the cursor when I move it between panels. I’m not sure what else to try, so any ideas would be greatly appreciated!! ginput, app designer, uifigure, pointer, plot MATLAB Answers — New Questions
Why do I get an error after changing the “getHeaderFile” method for an enum type to return a different header?
I am using MATLAB R2023b. I am trying to generate code from a Simulink model using Embedded Coder. I have an enum type, "myEnum". I set the header of this enum to "myHeader1.h" inside the "getHeaderFile" method. However, now I want to switch the header to "myHeader2.h", so I edited this method to return "myHeader2.h" instead. When I try this and then generate code, I get an error,
Error:The header file name myHeader1.h for data type ‘myEnum’ does not match the shared header file name myHeader2.h.
How do I work around this error?I am using MATLAB R2023b. I am trying to generate code from a Simulink model using Embedded Coder. I have an enum type, "myEnum". I set the header of this enum to "myHeader1.h" inside the "getHeaderFile" method. However, now I want to switch the header to "myHeader2.h", so I edited this method to return "myHeader2.h" instead. When I try this and then generate code, I get an error,
Error:The header file name myHeader1.h for data type ‘myEnum’ does not match the shared header file name myHeader2.h.
How do I work around this error? I am using MATLAB R2023b. I am trying to generate code from a Simulink model using Embedded Coder. I have an enum type, "myEnum". I set the header of this enum to "myHeader1.h" inside the "getHeaderFile" method. However, now I want to switch the header to "myHeader2.h", so I edited this method to return "myHeader2.h" instead. When I try this and then generate code, I get an error,
Error:The header file name myHeader1.h for data type ‘myEnum’ does not match the shared header file name myHeader2.h.
How do I work around this error? slxc, _sharedutils, header, enum, enumeration, sharedheader MATLAB Answers — New Questions