Category: Matlab
Category Archives: Matlab
How to make reusable a c2000 Embedded Coder block?
Hello,
I’m using Simulink blocks from "Embedded Coder Support Package for Texas Instruments C2000 Processors/F2837xD" library, however, when trying to control a GPIO from two different subsystems (which occurs not simultaneously) I get an error message when trying to compile since the block is not reusable. How can I do it reusable?
I’ve read something about "SS_OPTION_WORKS_WITH_CODE_REUSE" but I don’t know how to make specific blocks reusable, like the next one.
Thank you very much.
Best regards.Hello,
I’m using Simulink blocks from "Embedded Coder Support Package for Texas Instruments C2000 Processors/F2837xD" library, however, when trying to control a GPIO from two different subsystems (which occurs not simultaneously) I get an error message when trying to compile since the block is not reusable. How can I do it reusable?
I’ve read something about "SS_OPTION_WORKS_WITH_CODE_REUSE" but I don’t know how to make specific blocks reusable, like the next one.
Thank you very much.
Best regards. Hello,
I’m using Simulink blocks from "Embedded Coder Support Package for Texas Instruments C2000 Processors/F2837xD" library, however, when trying to control a GPIO from two different subsystems (which occurs not simultaneously) I get an error message when trying to compile since the block is not reusable. How can I do it reusable?
I’ve read something about "SS_OPTION_WORKS_WITH_CODE_REUSE" but I don’t know how to make specific blocks reusable, like the next one.
Thank you very much.
Best regards. embedded coder, c2000 embedded coder MATLAB Answers — New Questions
Make an image darker with overlay of another image
Hello,
I have two images I read into matrices that are displayed with imagesc. I was wondering if there’s a way to darken one image using the other image (like I could in Photoshop by using the darken overlay feature). I’ve looked into a few options, like imfuse, but haven’t had much luck. Any suggestions?Hello,
I have two images I read into matrices that are displayed with imagesc. I was wondering if there’s a way to darken one image using the other image (like I could in Photoshop by using the darken overlay feature). I’ve looked into a few options, like imfuse, but haven’t had much luck. Any suggestions? Hello,
I have two images I read into matrices that are displayed with imagesc. I was wondering if there’s a way to darken one image using the other image (like I could in Photoshop by using the darken overlay feature). I’ve looked into a few options, like imfuse, but haven’t had much luck. Any suggestions? image processing MATLAB Answers — New Questions
What is the problem in my code? Lambert-W function
I’m trying to solve a non-linear system of equations using Newton-Raphson method. The problem is in section 2.1 from this paper:
https://www.sciencedirect.com/science/article/pii/S0038092X14006094#t0010
It goes only up to the second iteration, and I got incorrect answer.
I used these values for iN and VN (N=1,2,3,4,5). V1 = 1.00400400e+00; V2 = 1.02598500e+00; V3 = 1.05325500e+00; V4 = 1.08812300e+00; V5 = 1.13388700e+00; i1 = -2.40036700e-02; i2 = -3.59849700e-02; i3 = -5.32552100e-02; i4 = -7.81225600e-02 ; i5 = -1.13887200e-01;
I used a = Iph, b = I0, f = n, c = Rs, d = Rsh, Vth = 0.0258
Here’s my code:
clear all; clc;
N = 20;
tErr = 1e-6;
syms a b c d f
V1 = 1.00400400e+00; V2 = 1.02598500e+00; V3 = 1.05325500e+00; V4 = 1.08812300e+00; V5 = 1.13388700e+00; i1 = -2.40036700e-02; i2 = -3.59849700e-02; i3 = -5.32552100e-02; i4 = -7.81225600e-02 ; i5 = -1.13887200e-01;
m1 = d*(-i1 + a + b)/(0.0258*f); m2 = d*(-i2 + a + b)/(0.0258*f); m3 = d*(-i3 + a + b)/(0.0258*f); m4 = d*(-i4 + a + b)/(0.0258*f);
m5 = d*(-i5 + a + b)/(0.0258*f); n = .0258*f; k = b*d/n;
f1 = -i1*c-i1*d+a*d-n*lambertw(b*d*exp(m1)/n)-V1;
f2 = -i2*c-i2*d+a*d-n*lambertw(b*d*exp(m2)/n)-V2;
f3 = -i3*c-i3*d+a*d-n*lambertw(b*d*exp(m3)/n)-V3;
f4 = -i4*c-i4*d+a*d-n*lambertw(b*d*exp(m4)/n)-V4;
f5 = -i5*c-i5*d+a*d-n*lambertw(b*d*exp(m5)/n)-V5;
fs = [f1; f2; f3; f4; f5];
xs = [a; b; f; c; d];
jac = [d/lambertw(b*d*exp(m1)/n), -(n*lambertw(b*d*exp(m1)/n)-b*d)/(b*(1+lambertw(b*d*exp(m1)/n))), lambertw(b*d*exp(m1)/n)*(-n*lambertw(b*d*exp(m1)/n)-i1*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m1)/n))), -i1, -(n*lambertw(b*d*exp(m1)/n)+i1*d-a*d-b*d)/((1+lambertw(b*d*exp(m1)/n))*d);
d/lambertw(b*d*exp(m2)/n), -(n*lambertw(b*d*exp(m2)/n)-b*d)/(b*(1+lambertw(b*d*exp(m2)/n))), lambertw(b*d*exp(m2)/n)*(-n*lambertw(b*d*exp(m2)/n)-i2*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m2)/n))), -i2, -(n*lambertw(b*d*exp(m2)/n)+i2*d-a*d-b*d)/((1+lambertw(b*d*exp(m2)/n))*d);
d/lambertw(b*d*exp(m3)/n), -(n*lambertw(b*d*exp(m3)/n)-b*d)/(b*(1+lambertw(b*d*exp(m3)/n))), lambertw(b*d*exp(m3)/n)*(-n*lambertw(b*d*exp(m3)/n)-i3*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m3)/n))), -i3, -(n*lambertw(b*d*exp(m3)/n)+i3*d-a*d-b*d)/((1+lambertw(b*d*exp(m3)/n))*d);
d/lambertw(b*d*exp(m4)/n), -(n*lambertw(b*d*exp(m4)/n)-b*d)/(b*(1+lambertw(b*d*exp(m4)/n))), lambertw(b*d*exp(m4)/n)*(-n*lambertw(b*d*exp(m4)/n)-i4*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m4)/n))), -i4, -(n*lambertw(b*d*exp(m4)/n)+i4*d-a*d-b*d)/((1+lambertw(b*d*exp(m4)/n))*d);
d/lambertw(b*d*exp(m5)/n), -(n*lambertw(b*d*exp(m5)/n)-b*d)/(b*(1+lambertw(b*d*exp(m5)/n))), lambertw(b*d*exp(m5)/n)*(-n*lambertw(b*d*exp(m5)/n)-i5*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m5)/n))), -i5, -(n*lambertw(b*d*exp(m5)/n)+i5*d-a*d-b*d)/((1+lambertw(b*d*exp(m5)/n))*d)];
x = [1.2; 0.001; 1.5; 1; 15];
for i=1:N
f = double(subs(fs, xs, x));
j = double(subs(jac, xs, x));
x = x – inv(j)*f;
err = abs(inv(j)*f);
if(err<tErr)
break;
end
end
display(x);I’m trying to solve a non-linear system of equations using Newton-Raphson method. The problem is in section 2.1 from this paper:
https://www.sciencedirect.com/science/article/pii/S0038092X14006094#t0010
It goes only up to the second iteration, and I got incorrect answer.
I used these values for iN and VN (N=1,2,3,4,5). V1 = 1.00400400e+00; V2 = 1.02598500e+00; V3 = 1.05325500e+00; V4 = 1.08812300e+00; V5 = 1.13388700e+00; i1 = -2.40036700e-02; i2 = -3.59849700e-02; i3 = -5.32552100e-02; i4 = -7.81225600e-02 ; i5 = -1.13887200e-01;
I used a = Iph, b = I0, f = n, c = Rs, d = Rsh, Vth = 0.0258
Here’s my code:
clear all; clc;
N = 20;
tErr = 1e-6;
syms a b c d f
V1 = 1.00400400e+00; V2 = 1.02598500e+00; V3 = 1.05325500e+00; V4 = 1.08812300e+00; V5 = 1.13388700e+00; i1 = -2.40036700e-02; i2 = -3.59849700e-02; i3 = -5.32552100e-02; i4 = -7.81225600e-02 ; i5 = -1.13887200e-01;
m1 = d*(-i1 + a + b)/(0.0258*f); m2 = d*(-i2 + a + b)/(0.0258*f); m3 = d*(-i3 + a + b)/(0.0258*f); m4 = d*(-i4 + a + b)/(0.0258*f);
m5 = d*(-i5 + a + b)/(0.0258*f); n = .0258*f; k = b*d/n;
f1 = -i1*c-i1*d+a*d-n*lambertw(b*d*exp(m1)/n)-V1;
f2 = -i2*c-i2*d+a*d-n*lambertw(b*d*exp(m2)/n)-V2;
f3 = -i3*c-i3*d+a*d-n*lambertw(b*d*exp(m3)/n)-V3;
f4 = -i4*c-i4*d+a*d-n*lambertw(b*d*exp(m4)/n)-V4;
f5 = -i5*c-i5*d+a*d-n*lambertw(b*d*exp(m5)/n)-V5;
fs = [f1; f2; f3; f4; f5];
xs = [a; b; f; c; d];
jac = [d/lambertw(b*d*exp(m1)/n), -(n*lambertw(b*d*exp(m1)/n)-b*d)/(b*(1+lambertw(b*d*exp(m1)/n))), lambertw(b*d*exp(m1)/n)*(-n*lambertw(b*d*exp(m1)/n)-i1*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m1)/n))), -i1, -(n*lambertw(b*d*exp(m1)/n)+i1*d-a*d-b*d)/((1+lambertw(b*d*exp(m1)/n))*d);
d/lambertw(b*d*exp(m2)/n), -(n*lambertw(b*d*exp(m2)/n)-b*d)/(b*(1+lambertw(b*d*exp(m2)/n))), lambertw(b*d*exp(m2)/n)*(-n*lambertw(b*d*exp(m2)/n)-i2*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m2)/n))), -i2, -(n*lambertw(b*d*exp(m2)/n)+i2*d-a*d-b*d)/((1+lambertw(b*d*exp(m2)/n))*d);
d/lambertw(b*d*exp(m3)/n), -(n*lambertw(b*d*exp(m3)/n)-b*d)/(b*(1+lambertw(b*d*exp(m3)/n))), lambertw(b*d*exp(m3)/n)*(-n*lambertw(b*d*exp(m3)/n)-i3*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m3)/n))), -i3, -(n*lambertw(b*d*exp(m3)/n)+i3*d-a*d-b*d)/((1+lambertw(b*d*exp(m3)/n))*d);
d/lambertw(b*d*exp(m4)/n), -(n*lambertw(b*d*exp(m4)/n)-b*d)/(b*(1+lambertw(b*d*exp(m4)/n))), lambertw(b*d*exp(m4)/n)*(-n*lambertw(b*d*exp(m4)/n)-i4*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m4)/n))), -i4, -(n*lambertw(b*d*exp(m4)/n)+i4*d-a*d-b*d)/((1+lambertw(b*d*exp(m4)/n))*d);
d/lambertw(b*d*exp(m5)/n), -(n*lambertw(b*d*exp(m5)/n)-b*d)/(b*(1+lambertw(b*d*exp(m5)/n))), lambertw(b*d*exp(m5)/n)*(-n*lambertw(b*d*exp(m5)/n)-i5*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m5)/n))), -i5, -(n*lambertw(b*d*exp(m5)/n)+i5*d-a*d-b*d)/((1+lambertw(b*d*exp(m5)/n))*d)];
x = [1.2; 0.001; 1.5; 1; 15];
for i=1:N
f = double(subs(fs, xs, x));
j = double(subs(jac, xs, x));
x = x – inv(j)*f;
err = abs(inv(j)*f);
if(err<tErr)
break;
end
end
display(x); I’m trying to solve a non-linear system of equations using Newton-Raphson method. The problem is in section 2.1 from this paper:
https://www.sciencedirect.com/science/article/pii/S0038092X14006094#t0010
It goes only up to the second iteration, and I got incorrect answer.
I used these values for iN and VN (N=1,2,3,4,5). V1 = 1.00400400e+00; V2 = 1.02598500e+00; V3 = 1.05325500e+00; V4 = 1.08812300e+00; V5 = 1.13388700e+00; i1 = -2.40036700e-02; i2 = -3.59849700e-02; i3 = -5.32552100e-02; i4 = -7.81225600e-02 ; i5 = -1.13887200e-01;
I used a = Iph, b = I0, f = n, c = Rs, d = Rsh, Vth = 0.0258
Here’s my code:
clear all; clc;
N = 20;
tErr = 1e-6;
syms a b c d f
V1 = 1.00400400e+00; V2 = 1.02598500e+00; V3 = 1.05325500e+00; V4 = 1.08812300e+00; V5 = 1.13388700e+00; i1 = -2.40036700e-02; i2 = -3.59849700e-02; i3 = -5.32552100e-02; i4 = -7.81225600e-02 ; i5 = -1.13887200e-01;
m1 = d*(-i1 + a + b)/(0.0258*f); m2 = d*(-i2 + a + b)/(0.0258*f); m3 = d*(-i3 + a + b)/(0.0258*f); m4 = d*(-i4 + a + b)/(0.0258*f);
m5 = d*(-i5 + a + b)/(0.0258*f); n = .0258*f; k = b*d/n;
f1 = -i1*c-i1*d+a*d-n*lambertw(b*d*exp(m1)/n)-V1;
f2 = -i2*c-i2*d+a*d-n*lambertw(b*d*exp(m2)/n)-V2;
f3 = -i3*c-i3*d+a*d-n*lambertw(b*d*exp(m3)/n)-V3;
f4 = -i4*c-i4*d+a*d-n*lambertw(b*d*exp(m4)/n)-V4;
f5 = -i5*c-i5*d+a*d-n*lambertw(b*d*exp(m5)/n)-V5;
fs = [f1; f2; f3; f4; f5];
xs = [a; b; f; c; d];
jac = [d/lambertw(b*d*exp(m1)/n), -(n*lambertw(b*d*exp(m1)/n)-b*d)/(b*(1+lambertw(b*d*exp(m1)/n))), lambertw(b*d*exp(m1)/n)*(-n*lambertw(b*d*exp(m1)/n)-i1*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m1)/n))), -i1, -(n*lambertw(b*d*exp(m1)/n)+i1*d-a*d-b*d)/((1+lambertw(b*d*exp(m1)/n))*d);
d/lambertw(b*d*exp(m2)/n), -(n*lambertw(b*d*exp(m2)/n)-b*d)/(b*(1+lambertw(b*d*exp(m2)/n))), lambertw(b*d*exp(m2)/n)*(-n*lambertw(b*d*exp(m2)/n)-i2*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m2)/n))), -i2, -(n*lambertw(b*d*exp(m2)/n)+i2*d-a*d-b*d)/((1+lambertw(b*d*exp(m2)/n))*d);
d/lambertw(b*d*exp(m3)/n), -(n*lambertw(b*d*exp(m3)/n)-b*d)/(b*(1+lambertw(b*d*exp(m3)/n))), lambertw(b*d*exp(m3)/n)*(-n*lambertw(b*d*exp(m3)/n)-i3*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m3)/n))), -i3, -(n*lambertw(b*d*exp(m3)/n)+i3*d-a*d-b*d)/((1+lambertw(b*d*exp(m3)/n))*d);
d/lambertw(b*d*exp(m4)/n), -(n*lambertw(b*d*exp(m4)/n)-b*d)/(b*(1+lambertw(b*d*exp(m4)/n))), lambertw(b*d*exp(m4)/n)*(-n*lambertw(b*d*exp(m4)/n)-i4*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m4)/n))), -i4, -(n*lambertw(b*d*exp(m4)/n)+i4*d-a*d-b*d)/((1+lambertw(b*d*exp(m4)/n))*d);
d/lambertw(b*d*exp(m5)/n), -(n*lambertw(b*d*exp(m5)/n)-b*d)/(b*(1+lambertw(b*d*exp(m5)/n))), lambertw(b*d*exp(m5)/n)*(-n*lambertw(b*d*exp(m5)/n)-i5*d+a*d+b*d)/(f*(1+lambertw(b*d*exp(m5)/n))), -i5, -(n*lambertw(b*d*exp(m5)/n)+i5*d-a*d-b*d)/((1+lambertw(b*d*exp(m5)/n))*d)];
x = [1.2; 0.001; 1.5; 1; 15];
for i=1:N
f = double(subs(fs, xs, x));
j = double(subs(jac, xs, x));
x = x – inv(j)*f;
err = abs(inv(j)*f);
if(err<tErr)
break;
end
end
display(x); #newtonmethod, #solve, #nonlinear MATLAB Answers — New Questions
Export Data + Another graphic
Hey,
I have a circuit in LTSPICE and I alredy exported the data to matlab. I created a plot.
But now, I have to add another plot to it so I can compare both of them. This second plot is a bode dyagram with a transfer function and I can make it work.
Can you guys help please?Hey,
I have a circuit in LTSPICE and I alredy exported the data to matlab. I created a plot.
But now, I have to add another plot to it so I can compare both of them. This second plot is a bode dyagram with a transfer function and I can make it work.
Can you guys help please? Hey,
I have a circuit in LTSPICE and I alredy exported the data to matlab. I created a plot.
But now, I have to add another plot to it so I can compare both of them. This second plot is a bode dyagram with a transfer function and I can make it work.
Can you guys help please? matlab, circuit MATLAB Answers — New Questions
Thingspeakwrite error when using string array
This string of code is taken from the thingSpeak documentation for matlab. I just copy and paste but still got this error. I would very much appreciate it if anyone can tell me where i did wrong
<</matlabcentral/answers/uploaded_files/94486/error.JPG>>This string of code is taken from the thingSpeak documentation for matlab. I just copy and paste but still got this error. I would very much appreciate it if anyone can tell me where i did wrong
<</matlabcentral/answers/uploaded_files/94486/error.JPG>> This string of code is taken from the thingSpeak documentation for matlab. I just copy and paste but still got this error. I would very much appreciate it if anyone can tell me where i did wrong
<</matlabcentral/answers/uploaded_files/94486/error.JPG>> thingspeak, matlab, string, iot MATLAB Answers — New Questions
Book recommendations for improving optimization, control and modeling different processes in MATLAB
Hi, I want to enhance my coding skills in optimization, simulation, and control of various processes using MATLAB. Could you suggest some books that would help me achieve this?Hi, I want to enhance my coding skills in optimization, simulation, and control of various processes using MATLAB. Could you suggest some books that would help me achieve this? Hi, I want to enhance my coding skills in optimization, simulation, and control of various processes using MATLAB. Could you suggest some books that would help me achieve this? book, control, optimization, model MATLAB Answers — New Questions
Is it possible to use of Matlab functions that do not support code generation in matlab.System objects?
I am working on developing a matlab.System and would like to leverage the speed advantage of running the model in complied mode.
The matlab engine interaction with the matlab.System object is described in – https://www.mathworks.com/help/simulink/ug/simulink-engine-interaction-with-system-objects.html
In order to maintain generality of code (i.e. I have a parent model superclass which specifies methods used by several subclasses – models that share a common framework), I need to use functions like metaclass that do not support code generation.
Is it possible to use functions such as metaclass in some of the implementation methods?I am working on developing a matlab.System and would like to leverage the speed advantage of running the model in complied mode.
The matlab engine interaction with the matlab.System object is described in – https://www.mathworks.com/help/simulink/ug/simulink-engine-interaction-with-system-objects.html
In order to maintain generality of code (i.e. I have a parent model superclass which specifies methods used by several subclasses – models that share a common framework), I need to use functions like metaclass that do not support code generation.
Is it possible to use functions such as metaclass in some of the implementation methods? I am working on developing a matlab.System and would like to leverage the speed advantage of running the model in complied mode.
The matlab engine interaction with the matlab.System object is described in – https://www.mathworks.com/help/simulink/ug/simulink-engine-interaction-with-system-objects.html
In order to maintain generality of code (i.e. I have a parent model superclass which specifies methods used by several subclasses – models that share a common framework), I need to use functions like metaclass that do not support code generation.
Is it possible to use functions such as metaclass in some of the implementation methods? matlab, simulink, matlab.system MATLAB Answers — New Questions
Is there any implementation of XGBoost algorithm for decision trees in Matlab?
I’ve found other boosting algos available in fitensemble and fitcensemble options but not XGBoost. Any chance to find it somewhere else?
Thanks
RobertoI’ve found other boosting algos available in fitensemble and fitcensemble options but not XGBoost. Any chance to find it somewhere else?
Thanks
Roberto I’ve found other boosting algos available in fitensemble and fitcensemble options but not XGBoost. Any chance to find it somewhere else?
Thanks
Roberto xgboost, machine learning, optimization, decision trees, boosting MATLAB Answers — New Questions
Index error running Psychtoolbox experiment
Dear Community,
I am running my experiment using Psychtoolbox. Unfortunately, I cannot share the whole script here, but generally it’s a centre-out reaching task where my participants use a joystick to reach targets. The joystick trajectory is being tracked with high temporal resolution and saved.
The tasks is presented using Psychtoolbox-3 (3.0.19) running on the MATLAB platform (2021b) in ubuntu (22.04).
The script works somewhat unstable. In 50 percent of cases it runs smoothly without any issues. In the other 50 percent it crushes with the following error message:
Identifier: MATLAB:badsubscript (line 643)
Error: Index in position 1 exceeds array bounds. Index must not exceed 552.
Error in function TextSize: Invalid Window (or Texture) Index provided: It doesn’t correspond to an open window or texture.
Did you close it accidentally via Screen(‘Close’) or Screen(‘CloseAll’) ?
Error using Screen
Usage:
oldTextSize=Screen(‘TextSize’, windowPtr [,textSize]);
Error in C_cued_cursor_rotation_joystick_noCentre (line 727)
Screen(‘TextSize’,wPtr, 40);
Here’s a few lines of my script with line 643 highlighted:
motion(:,9) = [NaN; ((velo/pix_per_mm)/1000)]; %convert velocity units to m/s
%store raw data
trialDat{trial} = motion;
%extract reach data
reachDat{trial} = motion(move_loc:endLoc,:); % LINE 643
%get velocity trend
reachDat{trial}(:,10) = trenddecomp(reachDat{trial}(:,9));
%identify max velocity from trend data
[maxVelo, maxLoc] = max(reachDat{trial}(:, 10));
I’m not a great expert in Matlab unfortunetely. What bugs me is that the script crushes at random time points. Sometimes after 50 trials, sometimes after 450+. And there seems to be nothing different im terms of participant’s performance compared to other trials.
Do you have any ideas what can cause this issue?
And why it doesn’t crush from the very first trial?Dear Community,
I am running my experiment using Psychtoolbox. Unfortunately, I cannot share the whole script here, but generally it’s a centre-out reaching task where my participants use a joystick to reach targets. The joystick trajectory is being tracked with high temporal resolution and saved.
The tasks is presented using Psychtoolbox-3 (3.0.19) running on the MATLAB platform (2021b) in ubuntu (22.04).
The script works somewhat unstable. In 50 percent of cases it runs smoothly without any issues. In the other 50 percent it crushes with the following error message:
Identifier: MATLAB:badsubscript (line 643)
Error: Index in position 1 exceeds array bounds. Index must not exceed 552.
Error in function TextSize: Invalid Window (or Texture) Index provided: It doesn’t correspond to an open window or texture.
Did you close it accidentally via Screen(‘Close’) or Screen(‘CloseAll’) ?
Error using Screen
Usage:
oldTextSize=Screen(‘TextSize’, windowPtr [,textSize]);
Error in C_cued_cursor_rotation_joystick_noCentre (line 727)
Screen(‘TextSize’,wPtr, 40);
Here’s a few lines of my script with line 643 highlighted:
motion(:,9) = [NaN; ((velo/pix_per_mm)/1000)]; %convert velocity units to m/s
%store raw data
trialDat{trial} = motion;
%extract reach data
reachDat{trial} = motion(move_loc:endLoc,:); % LINE 643
%get velocity trend
reachDat{trial}(:,10) = trenddecomp(reachDat{trial}(:,9));
%identify max velocity from trend data
[maxVelo, maxLoc] = max(reachDat{trial}(:, 10));
I’m not a great expert in Matlab unfortunetely. What bugs me is that the script crushes at random time points. Sometimes after 50 trials, sometimes after 450+. And there seems to be nothing different im terms of participant’s performance compared to other trials.
Do you have any ideas what can cause this issue?
And why it doesn’t crush from the very first trial? Dear Community,
I am running my experiment using Psychtoolbox. Unfortunately, I cannot share the whole script here, but generally it’s a centre-out reaching task where my participants use a joystick to reach targets. The joystick trajectory is being tracked with high temporal resolution and saved.
The tasks is presented using Psychtoolbox-3 (3.0.19) running on the MATLAB platform (2021b) in ubuntu (22.04).
The script works somewhat unstable. In 50 percent of cases it runs smoothly without any issues. In the other 50 percent it crushes with the following error message:
Identifier: MATLAB:badsubscript (line 643)
Error: Index in position 1 exceeds array bounds. Index must not exceed 552.
Error in function TextSize: Invalid Window (or Texture) Index provided: It doesn’t correspond to an open window or texture.
Did you close it accidentally via Screen(‘Close’) or Screen(‘CloseAll’) ?
Error using Screen
Usage:
oldTextSize=Screen(‘TextSize’, windowPtr [,textSize]);
Error in C_cued_cursor_rotation_joystick_noCentre (line 727)
Screen(‘TextSize’,wPtr, 40);
Here’s a few lines of my script with line 643 highlighted:
motion(:,9) = [NaN; ((velo/pix_per_mm)/1000)]; %convert velocity units to m/s
%store raw data
trialDat{trial} = motion;
%extract reach data
reachDat{trial} = motion(move_loc:endLoc,:); % LINE 643
%get velocity trend
reachDat{trial}(:,10) = trenddecomp(reachDat{trial}(:,9));
%identify max velocity from trend data
[maxVelo, maxLoc] = max(reachDat{trial}(:, 10));
I’m not a great expert in Matlab unfortunetely. What bugs me is that the script crushes at random time points. Sometimes after 50 trials, sometimes after 450+. And there seems to be nothing different im terms of participant’s performance compared to other trials.
Do you have any ideas what can cause this issue?
And why it doesn’t crush from the very first trial? psychtoolbox MATLAB Answers — New Questions
Simulink start page stuck on infinite loading screen
I am using Matlab 2022b. This is the behavior I get when opening Matlab.
Selecting the Matlab application once will open two seperate Matlab windows.
Matlab itself runs fine (I can run
Opening Simulink loads the Simulink start page and once I select a project it gets stuck in an infinite loading loop. I have tried reinstalling and I get the same behavior.I am using Matlab 2022b. This is the behavior I get when opening Matlab.
Selecting the Matlab application once will open two seperate Matlab windows.
Matlab itself runs fine (I can run
Opening Simulink loads the Simulink start page and once I select a project it gets stuck in an infinite loading loop. I have tried reinstalling and I get the same behavior. I am using Matlab 2022b. This is the behavior I get when opening Matlab.
Selecting the Matlab application once will open two seperate Matlab windows.
Matlab itself runs fine (I can run
Opening Simulink loads the Simulink start page and once I select a project it gets stuck in an infinite loading loop. I have tried reinstalling and I get the same behavior. simulink MATLAB Answers — New Questions
Solve ill-conditioned linear systems
Consider the following linear system of equations :
When solving this system using MATLAB, I found that the condition number of matrix is extremely large, indicating that the system is ill-conditioned. Some characteristics of the system are as follows:
Condition number of : 2.715e+06
Determinant of : 0.5196
I have attempted several methods, including least squares, normalization, and regularization, but none have produced satisfactory results in terms of accuracy. The matrix and is currently stored as double type, and I have also tried using ‘vpa’ to control the number of significant digits, but it was in vain. Are there any effective methods to solve this system, or is it possible to identify and eliminate highly correlated row vectors to ensure the accuracy of the remaining solutions?
Matlab data ‘.mat’:
https://1drv.ms/u/s!AlQCuPoSp7emgaNizYy43ea4fhgecg?e=vd3ubh
%% Load data
load("cal_linear_equations.mat");
%% Evaluate and calculate
DET_A=det(A_coeff);
Cond_A=cond(A_coeff);
Sol_real=A_coeffb_coeff;
Error=A_coeff*Sol_real-b_coeff;
max(abs(Error));Consider the following linear system of equations :
When solving this system using MATLAB, I found that the condition number of matrix is extremely large, indicating that the system is ill-conditioned. Some characteristics of the system are as follows:
Condition number of : 2.715e+06
Determinant of : 0.5196
I have attempted several methods, including least squares, normalization, and regularization, but none have produced satisfactory results in terms of accuracy. The matrix and is currently stored as double type, and I have also tried using ‘vpa’ to control the number of significant digits, but it was in vain. Are there any effective methods to solve this system, or is it possible to identify and eliminate highly correlated row vectors to ensure the accuracy of the remaining solutions?
Matlab data ‘.mat’:
https://1drv.ms/u/s!AlQCuPoSp7emgaNizYy43ea4fhgecg?e=vd3ubh
%% Load data
load("cal_linear_equations.mat");
%% Evaluate and calculate
DET_A=det(A_coeff);
Cond_A=cond(A_coeff);
Sol_real=A_coeffb_coeff;
Error=A_coeff*Sol_real-b_coeff;
max(abs(Error)); Consider the following linear system of equations :
When solving this system using MATLAB, I found that the condition number of matrix is extremely large, indicating that the system is ill-conditioned. Some characteristics of the system are as follows:
Condition number of : 2.715e+06
Determinant of : 0.5196
I have attempted several methods, including least squares, normalization, and regularization, but none have produced satisfactory results in terms of accuracy. The matrix and is currently stored as double type, and I have also tried using ‘vpa’ to control the number of significant digits, but it was in vain. Are there any effective methods to solve this system, or is it possible to identify and eliminate highly correlated row vectors to ensure the accuracy of the remaining solutions?
Matlab data ‘.mat’:
https://1drv.ms/u/s!AlQCuPoSp7emgaNizYy43ea4fhgecg?e=vd3ubh
%% Load data
load("cal_linear_equations.mat");
%% Evaluate and calculate
DET_A=det(A_coeff);
Cond_A=cond(A_coeff);
Sol_real=A_coeffb_coeff;
Error=A_coeff*Sol_real-b_coeff;
max(abs(Error)); linear equations, equation, system MATLAB Answers — New Questions
What is the Proper Notation for Multi-level Mixed Effects Models
I am a little confused on the proper syntax/notation for multi-level mxied effects models and was wondering what the proper way to write the formula is for these in Matlab? The results for either syntax appear identical except the BLUP names from calling "randomEffects" are different.
From the Multilevel Mixed-Effects Modeling Using MATLAB where state is nested within region they use the syntax (1|REGION) + (1|STATE:REGION).
However, from the fitlme description where to "j th tomato type nested in the k th soil type" the notation used is (1|Soil) + (1|Soil:Tomato).
Thanks,
SethI am a little confused on the proper syntax/notation for multi-level mxied effects models and was wondering what the proper way to write the formula is for these in Matlab? The results for either syntax appear identical except the BLUP names from calling "randomEffects" are different.
From the Multilevel Mixed-Effects Modeling Using MATLAB where state is nested within region they use the syntax (1|REGION) + (1|STATE:REGION).
However, from the fitlme description where to "j th tomato type nested in the k th soil type" the notation used is (1|Soil) + (1|Soil:Tomato).
Thanks,
Seth I am a little confused on the proper syntax/notation for multi-level mxied effects models and was wondering what the proper way to write the formula is for these in Matlab? The results for either syntax appear identical except the BLUP names from calling "randomEffects" are different.
From the Multilevel Mixed-Effects Modeling Using MATLAB where state is nested within region they use the syntax (1|REGION) + (1|STATE:REGION).
However, from the fitlme description where to "j th tomato type nested in the k th soil type" the notation used is (1|Soil) + (1|Soil:Tomato).
Thanks,
Seth fitglme, fitlme MATLAB Answers — New Questions
how to change latex default font in figure?
set(STA1,’A_Label’,’String’,’$(i+n)-C_{10}$’,’Interpreter’,’latex’,’FontSize’,18,’FontWeight’,’bold’)
When I use latex interpreter ,it can‘t use Times new roman style。how to solve this problem?
(在使用Latex编译器画图时,发现只能使用默认字体,不能更改为新罗马字体,如何解决?)set(STA1,’A_Label’,’String’,’$(i+n)-C_{10}$’,’Interpreter’,’latex’,’FontSize’,18,’FontWeight’,’bold’)
When I use latex interpreter ,it can‘t use Times new roman style。how to solve this problem?
(在使用Latex编译器画图时,发现只能使用默认字体,不能更改为新罗马字体,如何解决?) set(STA1,’A_Label’,’String’,’$(i+n)-C_{10}$’,’Interpreter’,’latex’,’FontSize’,18,’FontWeight’,’bold’)
When I use latex interpreter ,it can‘t use Times new roman style。how to solve this problem?
(在使用Latex编译器画图时,发现只能使用默认字体,不能更改为新罗马字体,如何解决?) latex, fontname, times new roman MATLAB Answers — New Questions
Cannot find an ADALM-PLUTO radio.
Hi,
at the end of the installation of the Support Package "Communications Toolbox Support Package for Analog Devices ADALM-Pluto Radio" I get an "Hardware Setup Error" that the Adalm-Pluto cannot be found. A view to WIndows System shows the Adalm Pluto.
I tried to unistall an install several times, but it dindn’t help.
MATLAB Version: 9.3.0.713579 (R2017b)
Operating System: Microsoft Windows 10 Home Version 10.0 (Build 17134)Hi,
at the end of the installation of the Support Package "Communications Toolbox Support Package for Analog Devices ADALM-Pluto Radio" I get an "Hardware Setup Error" that the Adalm-Pluto cannot be found. A view to WIndows System shows the Adalm Pluto.
I tried to unistall an install several times, but it dindn’t help.
MATLAB Version: 9.3.0.713579 (R2017b)
Operating System: Microsoft Windows 10 Home Version 10.0 (Build 17134) Hi,
at the end of the installation of the Support Package "Communications Toolbox Support Package for Analog Devices ADALM-Pluto Radio" I get an "Hardware Setup Error" that the Adalm-Pluto cannot be found. A view to WIndows System shows the Adalm Pluto.
I tried to unistall an install several times, but it dindn’t help.
MATLAB Version: 9.3.0.713579 (R2017b)
Operating System: Microsoft Windows 10 Home Version 10.0 (Build 17134) adalm-pluto MATLAB Answers — New Questions
Non-zero Gaussian noise in image processing
How can i Generate Gaussian Noise with a non zero meadian?
i found this code put i do not understand the division by 256.
where (I) is the cameraman image.
%Generating Gaussian Noise
mean= 40/256; Std= 20; var=(Std/256)^2;
G=imnoise(I,’gaussian’,mean,var);
imshow(G)
title (‘Image with Gaussian Noise’)How can i Generate Gaussian Noise with a non zero meadian?
i found this code put i do not understand the division by 256.
where (I) is the cameraman image.
%Generating Gaussian Noise
mean= 40/256; Std= 20; var=(Std/256)^2;
G=imnoise(I,’gaussian’,mean,var);
imshow(G)
title (‘Image with Gaussian Noise’) How can i Generate Gaussian Noise with a non zero meadian?
i found this code put i do not understand the division by 256.
where (I) is the cameraman image.
%Generating Gaussian Noise
mean= 40/256; Std= 20; var=(Std/256)^2;
G=imnoise(I,’gaussian’,mean,var);
imshow(G)
title (‘Image with Gaussian Noise’) gaussian noise, digital image processing, gaussian noise with non zero median MATLAB Answers — New Questions
how to apply mask on image of a size
I have apply noise to an image, now I would like to add mask on the image of size 3×3.
This is the code I am using to add noise but not able to add mask in it.
I = imread(‘sample2.jpg’);
I = rgb2gray(I);
noise_type = ‘salt & pepper’; % ‘gaussian’ or ‘poisson’ are also valid
noises = imnoise(im, noise_type, 0.09);
nim = im;
nim(noises == 0) = 0;
%# plot
figure; subplot(1,2,1);
imagesc(nim);
colormap(gray);
title(‘the noisy image’);I have apply noise to an image, now I would like to add mask on the image of size 3×3.
This is the code I am using to add noise but not able to add mask in it.
I = imread(‘sample2.jpg’);
I = rgb2gray(I);
noise_type = ‘salt & pepper’; % ‘gaussian’ or ‘poisson’ are also valid
noises = imnoise(im, noise_type, 0.09);
nim = im;
nim(noises == 0) = 0;
%# plot
figure; subplot(1,2,1);
imagesc(nim);
colormap(gray);
title(‘the noisy image’); I have apply noise to an image, now I would like to add mask on the image of size 3×3.
This is the code I am using to add noise but not able to add mask in it.
I = imread(‘sample2.jpg’);
I = rgb2gray(I);
noise_type = ‘salt & pepper’; % ‘gaussian’ or ‘poisson’ are also valid
noises = imnoise(im, noise_type, 0.09);
nim = im;
nim(noises == 0) = 0;
%# plot
figure; subplot(1,2,1);
imagesc(nim);
colormap(gray);
title(‘the noisy image’); mask on image MATLAB Answers — New Questions
How to generate c code for simulink example model, but just for a certain block.
I am using simulink example model titled "Grid tied inverter optimal current control" and i want to generate the c code for hardware implementation for the TI F28379D device. The issue is , the c code generted create dmany lines of code for the whole model but i just want the controller (DSP) code. how do i do that?I am using simulink example model titled "Grid tied inverter optimal current control" and i want to generate the c code for hardware implementation for the TI F28379D device. The issue is , the c code generted create dmany lines of code for the whole model but i just want the controller (DSP) code. how do i do that? I am using simulink example model titled "Grid tied inverter optimal current control" and i want to generate the c code for hardware implementation for the TI F28379D device. The issue is , the c code generted create dmany lines of code for the whole model but i just want the controller (DSP) code. how do i do that? simulink, code generation, dsp, hardware, embedded coder MATLAB Answers — New Questions
How do I correct the ‘Invalid root outport connection in the referenced model ‘referenced_model’ error in Simulink 7.2 (R2008a)?
I have a model, which contains a referenced model. When I update the main model I receive the following error:
ERROR: Invalid root outport connection in the referenced model ‘referenced_model’. Two different blocks drive the root Outport block 1. To be a valid connection, the root Outport block must be driven by one source port. Use the ‘Invalid Root Inport and Outport block connection’ option on the ‘Model Referencing’ group of the Diagnostics page of the Configuration Parameters dialog box to control reporting of this condition.
What can I do in order to avoid this error?I have a model, which contains a referenced model. When I update the main model I receive the following error:
ERROR: Invalid root outport connection in the referenced model ‘referenced_model’. Two different blocks drive the root Outport block 1. To be a valid connection, the root Outport block must be driven by one source port. Use the ‘Invalid Root Inport and Outport block connection’ option on the ‘Model Referencing’ group of the Diagnostics page of the Configuration Parameters dialog box to control reporting of this condition.
What can I do in order to avoid this error? I have a model, which contains a referenced model. When I update the main model I receive the following error:
ERROR: Invalid root outport connection in the referenced model ‘referenced_model’. Two different blocks drive the root Outport block 1. To be a valid connection, the root Outport block must be driven by one source port. Use the ‘Invalid Root Inport and Outport block connection’ option on the ‘Model Referencing’ group of the Diagnostics page of the Configuration Parameters dialog box to control reporting of this condition.
What can I do in order to avoid this error? MATLAB Answers — New Questions
image overlays to make playing card
Hi I am trying to overlap a picture of a red diamond ontop of another image that I created so that it looks like a playing card. Bleow is the script for the playing card is there a way to combine the red diamond image ontop of the mona lisa?
The mona.lisa.jpg was a just a random jpg i found of mona lisa and crop/coppied/and then flipped to give the effect of a playing card
Also the red diamond was just an image that i pulled off the internet
pic = imread(‘monalisa.jpg’);
top_mona = pic(1:550, 1:743, :);
flipped_mona = imrotate(top_mona,180,’bicubic’);
complete_card = [top_mona; flipped_mona];
imshow(complete_card)Hi I am trying to overlap a picture of a red diamond ontop of another image that I created so that it looks like a playing card. Bleow is the script for the playing card is there a way to combine the red diamond image ontop of the mona lisa?
The mona.lisa.jpg was a just a random jpg i found of mona lisa and crop/coppied/and then flipped to give the effect of a playing card
Also the red diamond was just an image that i pulled off the internet
pic = imread(‘monalisa.jpg’);
top_mona = pic(1:550, 1:743, :);
flipped_mona = imrotate(top_mona,180,’bicubic’);
complete_card = [top_mona; flipped_mona];
imshow(complete_card) Hi I am trying to overlap a picture of a red diamond ontop of another image that I created so that it looks like a playing card. Bleow is the script for the playing card is there a way to combine the red diamond image ontop of the mona lisa?
The mona.lisa.jpg was a just a random jpg i found of mona lisa and crop/coppied/and then flipped to give the effect of a playing card
Also the red diamond was just an image that i pulled off the internet
pic = imread(‘monalisa.jpg’);
top_mona = pic(1:550, 1:743, :);
flipped_mona = imrotate(top_mona,180,’bicubic’);
complete_card = [top_mona; flipped_mona];
imshow(complete_card) overlaping images MATLAB Answers — New Questions
GammatoneFIlterBank produces different results inside/outside user function
This post may be difficult to answer because the data I’m using can’t be released to the public (yet)…
I’m running chirp sweep responses through Matlab’s built-in gammatonefilterbank structure. I have to process thousands of files in this way and so I pass the filter object and several waveform matrices to a function that I’ve written. As part of my function, I run the lines
signal_reference = sweeps_averaged(first_index:first_index+49999,3,i);
A = gammaFiltBank(signal_reference);
plot(A);
which, for the waveform in question, produces the graph below when I pause afterwards. Notice the large spikes at the beginning of the filtered outputs.
If I pause in the debugger and run those exact same lines again, I get the following graph of outputs below. Notice that the spikes are now gone.
Of the thousands of waveforms that I need to process, this error only occurs in roughly half a dozen of them. I can cut off the first 1000ish samples and get good results, but it’s forcing me to question the results overall – I’m not sure if the filter bank is producing other errors that I’m unaware of until I know the root cause.
Any thoughts on what might be causing this? Am I missing something simple? I’m using R2022A on a Windows 11 64-bit Dell desktop.This post may be difficult to answer because the data I’m using can’t be released to the public (yet)…
I’m running chirp sweep responses through Matlab’s built-in gammatonefilterbank structure. I have to process thousands of files in this way and so I pass the filter object and several waveform matrices to a function that I’ve written. As part of my function, I run the lines
signal_reference = sweeps_averaged(first_index:first_index+49999,3,i);
A = gammaFiltBank(signal_reference);
plot(A);
which, for the waveform in question, produces the graph below when I pause afterwards. Notice the large spikes at the beginning of the filtered outputs.
If I pause in the debugger and run those exact same lines again, I get the following graph of outputs below. Notice that the spikes are now gone.
Of the thousands of waveforms that I need to process, this error only occurs in roughly half a dozen of them. I can cut off the first 1000ish samples and get good results, but it’s forcing me to question the results overall – I’m not sure if the filter bank is producing other errors that I’m unaware of until I know the root cause.
Any thoughts on what might be causing this? Am I missing something simple? I’m using R2022A on a Windows 11 64-bit Dell desktop. This post may be difficult to answer because the data I’m using can’t be released to the public (yet)…
I’m running chirp sweep responses through Matlab’s built-in gammatonefilterbank structure. I have to process thousands of files in this way and so I pass the filter object and several waveform matrices to a function that I’ve written. As part of my function, I run the lines
signal_reference = sweeps_averaged(first_index:first_index+49999,3,i);
A = gammaFiltBank(signal_reference);
plot(A);
which, for the waveform in question, produces the graph below when I pause afterwards. Notice the large spikes at the beginning of the filtered outputs.
If I pause in the debugger and run those exact same lines again, I get the following graph of outputs below. Notice that the spikes are now gone.
Of the thousands of waveforms that I need to process, this error only occurs in roughly half a dozen of them. I can cut off the first 1000ish samples and get good results, but it’s forcing me to question the results overall – I’m not sure if the filter bank is producing other errors that I’m unaware of until I know the root cause.
Any thoughts on what might be causing this? Am I missing something simple? I’m using R2022A on a Windows 11 64-bit Dell desktop. gammatonefilterbank, filtering MATLAB Answers — New Questions