Tag Archives: matlab
Make a plot with gradient shaded confidence intervals
Dear all,
I would like to fill the red shaded area in the plot below using a gradient fill (ideally with a jet colormap), so that the area between the blue line and the upper red dashed line goes from red to blue and the area between the blue line and the lower red dashed line goes from red to blue.
x = Data(:,1);
y = Data(:,2);
y10 = Data(:,3);
y90 = Data(:,4);
figure
plot(x, y, ‘b’, ‘LineWidth’, 2);
hold on;
plot(x, y10, ‘–r’);
plot(x, y90, ‘–r’);
fill([x; flipud(x)], [y10; flipud(y90)], ‘r’,…
‘FaceAlpha’, 0.1, ‘EdgeColor’, ‘none’);
hold off;
legend(‘Median’, ’10th-90th Percentiles’, ‘Location’, ‘best’);
grid on;
Just to give an idea, something like this (without color steps but with a gradient fill):
I have tried myself, but I can’t really find a nice (and fast) solution.
I have attched the Data file.
Any help would be grately appreciated!Dear all,
I would like to fill the red shaded area in the plot below using a gradient fill (ideally with a jet colormap), so that the area between the blue line and the upper red dashed line goes from red to blue and the area between the blue line and the lower red dashed line goes from red to blue.
x = Data(:,1);
y = Data(:,2);
y10 = Data(:,3);
y90 = Data(:,4);
figure
plot(x, y, ‘b’, ‘LineWidth’, 2);
hold on;
plot(x, y10, ‘–r’);
plot(x, y90, ‘–r’);
fill([x; flipud(x)], [y10; flipud(y90)], ‘r’,…
‘FaceAlpha’, 0.1, ‘EdgeColor’, ‘none’);
hold off;
legend(‘Median’, ’10th-90th Percentiles’, ‘Location’, ‘best’);
grid on;
Just to give an idea, something like this (without color steps but with a gradient fill):
I have tried myself, but I can’t really find a nice (and fast) solution.
I have attched the Data file.
Any help would be grately appreciated! Dear all,
I would like to fill the red shaded area in the plot below using a gradient fill (ideally with a jet colormap), so that the area between the blue line and the upper red dashed line goes from red to blue and the area between the blue line and the lower red dashed line goes from red to blue.
x = Data(:,1);
y = Data(:,2);
y10 = Data(:,3);
y90 = Data(:,4);
figure
plot(x, y, ‘b’, ‘LineWidth’, 2);
hold on;
plot(x, y10, ‘–r’);
plot(x, y90, ‘–r’);
fill([x; flipud(x)], [y10; flipud(y90)], ‘r’,…
‘FaceAlpha’, 0.1, ‘EdgeColor’, ‘none’);
hold off;
legend(‘Median’, ’10th-90th Percentiles’, ‘Location’, ‘best’);
grid on;
Just to give an idea, something like this (without color steps but with a gradient fill):
I have tried myself, but I can’t really find a nice (and fast) solution.
I have attched the Data file.
Any help would be grately appreciated! plotting, plot, colormap, graph, graphics, matlab MATLAB Answers — New Questions
Coloring area between two graphs in specific interval
Hi,
I have a plot that looks as shown and would like to color specific areas of it. In the blue graph, I would like shade the area of the minimum, so roughly between 100 < x < 115 and up to y = 0.45 (the area below the baseline).
I had no success doing this using a linear function and the inBetween and fill functions.
Thanks a lot,
ChrisHi,
I have a plot that looks as shown and would like to color specific areas of it. In the blue graph, I would like shade the area of the minimum, so roughly between 100 < x < 115 and up to y = 0.45 (the area below the baseline).
I had no success doing this using a linear function and the inBetween and fill functions.
Thanks a lot,
Chris Hi,
I have a plot that looks as shown and would like to color specific areas of it. In the blue graph, I would like shade the area of the minimum, so roughly between 100 < x < 115 and up to y = 0.45 (the area below the baseline).
I had no success doing this using a linear function and the inBetween and fill functions.
Thanks a lot,
Chris integral, area coloring MATLAB Answers — New Questions
I want to calculate basic reproduction number, how to make 6×6 matrix and also how to add different parameter
My basic reproduction number includes certain mathematical symbols which I am not able to write in matlab programming, how will I be able to calculate basic reproduction number? In other words how to code R0My basic reproduction number includes certain mathematical symbols which I am not able to write in matlab programming, how will I be able to calculate basic reproduction number? In other words how to code R0 My basic reproduction number includes certain mathematical symbols which I am not able to write in matlab programming, how will I be able to calculate basic reproduction number? In other words how to code R0 basic reproduction number MATLAB Answers — New Questions
about the starData.mat
Can anyone please tell how to download starData.mat file on pc. and please post the content of that file if possible I am unable to download it.Can anyone please tell how to download starData.mat file on pc. and please post the content of that file if possible I am unable to download it. Can anyone please tell how to download starData.mat file on pc. and please post the content of that file if possible I am unable to download it. stardata MATLAB Answers — New Questions
Problem with legend: colors don’t match value of variable
hello, i have a problem with the legend in this script: i am doing subplots for the two parameters e and t, in every subplot e is fixed while t can vary between 5 different values. the problem is the legend doesn’t match the colors. for instance, t= -50 should be red, -25 green, 0 blue, 25 light blue and t = 50 black, but the legend doesnt say this. Could anybody give me any suggestions on how to index the color and the value of the parameter so that they match? thank you
here is the code:
clear; clc; clf;
n = 1001;
x = linspace(-100, 100, n);
y = linspace(-100, 100, n);
[X, Y] = meshgrid(x, y);
clr = [‘r’,’g’,’b’,’c’,’k’];
a = 4;
e = [-50 -10 0 50];
t = linspace(-50, 50, 5);
LegendsStrings = cell(length(t),1);
for q = 1:a
for r = 1:5
Z = fn(X, Y, e(q), t(r), n);
subplot(2, 2, q)
xline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);
yline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);
hold on
v = [0, 0];
contour(X, Y, Z, v, ‘LineWidth’, 1.5, ‘LineColor’, clr(r))
xlabel(‘x’)
ylabel(‘y’)
title("e = " + e(q))
grid on
axis equal
hold off
LegendsStrings{r} = [‘t = ‘, num2str(t(r))];
end
legend(LegendsStrings, ‘Interpreter’, ‘none’)
end
function Z = fn(X,Y,e,t,n)
Z = zeros(n, n);
B = X + Y + e + t;
D = X.*Y – e.*t;
for i= 1:n
for j= 1:n
if B(i,j) >= 0
Z(i,j) = D(i,j);
else
Z(i,j) = -1;
end
end
end
endhello, i have a problem with the legend in this script: i am doing subplots for the two parameters e and t, in every subplot e is fixed while t can vary between 5 different values. the problem is the legend doesn’t match the colors. for instance, t= -50 should be red, -25 green, 0 blue, 25 light blue and t = 50 black, but the legend doesnt say this. Could anybody give me any suggestions on how to index the color and the value of the parameter so that they match? thank you
here is the code:
clear; clc; clf;
n = 1001;
x = linspace(-100, 100, n);
y = linspace(-100, 100, n);
[X, Y] = meshgrid(x, y);
clr = [‘r’,’g’,’b’,’c’,’k’];
a = 4;
e = [-50 -10 0 50];
t = linspace(-50, 50, 5);
LegendsStrings = cell(length(t),1);
for q = 1:a
for r = 1:5
Z = fn(X, Y, e(q), t(r), n);
subplot(2, 2, q)
xline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);
yline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);
hold on
v = [0, 0];
contour(X, Y, Z, v, ‘LineWidth’, 1.5, ‘LineColor’, clr(r))
xlabel(‘x’)
ylabel(‘y’)
title("e = " + e(q))
grid on
axis equal
hold off
LegendsStrings{r} = [‘t = ‘, num2str(t(r))];
end
legend(LegendsStrings, ‘Interpreter’, ‘none’)
end
function Z = fn(X,Y,e,t,n)
Z = zeros(n, n);
B = X + Y + e + t;
D = X.*Y – e.*t;
for i= 1:n
for j= 1:n
if B(i,j) >= 0
Z(i,j) = D(i,j);
else
Z(i,j) = -1;
end
end
end
end hello, i have a problem with the legend in this script: i am doing subplots for the two parameters e and t, in every subplot e is fixed while t can vary between 5 different values. the problem is the legend doesn’t match the colors. for instance, t= -50 should be red, -25 green, 0 blue, 25 light blue and t = 50 black, but the legend doesnt say this. Could anybody give me any suggestions on how to index the color and the value of the parameter so that they match? thank you
here is the code:
clear; clc; clf;
n = 1001;
x = linspace(-100, 100, n);
y = linspace(-100, 100, n);
[X, Y] = meshgrid(x, y);
clr = [‘r’,’g’,’b’,’c’,’k’];
a = 4;
e = [-50 -10 0 50];
t = linspace(-50, 50, 5);
LegendsStrings = cell(length(t),1);
for q = 1:a
for r = 1:5
Z = fn(X, Y, e(q), t(r), n);
subplot(2, 2, q)
xline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);
yline(0, ‘Color’, ‘k’, ‘LineWidth’, 0.5);
hold on
v = [0, 0];
contour(X, Y, Z, v, ‘LineWidth’, 1.5, ‘LineColor’, clr(r))
xlabel(‘x’)
ylabel(‘y’)
title("e = " + e(q))
grid on
axis equal
hold off
LegendsStrings{r} = [‘t = ‘, num2str(t(r))];
end
legend(LegendsStrings, ‘Interpreter’, ‘none’)
end
function Z = fn(X,Y,e,t,n)
Z = zeros(n, n);
B = X + Y + e + t;
D = X.*Y – e.*t;
for i= 1:n
for j= 1:n
if B(i,j) >= 0
Z(i,j) = D(i,j);
else
Z(i,j) = -1;
end
end
end
end legend, colorstring, indexing, plot, subplot, color MATLAB Answers — New Questions
Calculating with different date times
Hi,
I have one array that contains my speed during running and the corresponding time it was recorded at. Measurements are about every one second.
Then I have a second array that contains my heart rate measurements and the corresponding time they were recorded at. These measurements contain data from about every 6-10 seconds.
This is shown by the exemplary screenshot.
What I am trying to do is divide my speed by heart rate at the corresponding times to get something like ‘performance’. So I need to average the speed of all measurements that were done for one measurement of heart rate. Something like this:
mean(Speed(1:6))/Heartrate(1)
mean(Speed(7:16))/Heartrate(2)
I cannot do this by hand for the amount of data but have problems coming up with code that selects the correct time range to average the speed (the time range that corresponds to every one measurement of heart rate) and then divides these values.
I appreciate your ideas/ help!
PS Sorry for the bad question title, I couldn’t think of a better one :/Hi,
I have one array that contains my speed during running and the corresponding time it was recorded at. Measurements are about every one second.
Then I have a second array that contains my heart rate measurements and the corresponding time they were recorded at. These measurements contain data from about every 6-10 seconds.
This is shown by the exemplary screenshot.
What I am trying to do is divide my speed by heart rate at the corresponding times to get something like ‘performance’. So I need to average the speed of all measurements that were done for one measurement of heart rate. Something like this:
mean(Speed(1:6))/Heartrate(1)
mean(Speed(7:16))/Heartrate(2)
I cannot do this by hand for the amount of data but have problems coming up with code that selects the correct time range to average the speed (the time range that corresponds to every one measurement of heart rate) and then divides these values.
I appreciate your ideas/ help!
PS Sorry for the bad question title, I couldn’t think of a better one :/ Hi,
I have one array that contains my speed during running and the corresponding time it was recorded at. Measurements are about every one second.
Then I have a second array that contains my heart rate measurements and the corresponding time they were recorded at. These measurements contain data from about every 6-10 seconds.
This is shown by the exemplary screenshot.
What I am trying to do is divide my speed by heart rate at the corresponding times to get something like ‘performance’. So I need to average the speed of all measurements that were done for one measurement of heart rate. Something like this:
mean(Speed(1:6))/Heartrate(1)
mean(Speed(7:16))/Heartrate(2)
I cannot do this by hand for the amount of data but have problems coming up with code that selects the correct time range to average the speed (the time range that corresponds to every one measurement of heart rate) and then divides these values.
I appreciate your ideas/ help!
PS Sorry for the bad question title, I couldn’t think of a better one :/ datetime MATLAB Answers — New Questions
Undefined function ‘dts_cast_with_warning’ for input arguments of type ‘matlab.ui.Figure’.
Hello,
I’m implementing a function in mex file (on GPU) in MALTLAB. But I faced with the following error in MATLAB:
Undefined function ‘dts_cast_with_warning’ for input arguments of type ‘matlab.ui.Figure’.
Error in BPmimo2C (line 98)
figure
Error in test (line 29)
BPmimo2C_mex( Efield, f_par, xyz_par, TX, TY, numT, numR)
Here is where this error occurred (in the "figure" part):
…
…
…
for j = 1:numel(z)
hf(j,:,:) = z(j);
end
figure %************** here is where the error occurred
% figure(1);
er = squeeze(max(image,[],1));
h = surf(squeeze(uf(1,:,:)),squeeze(vf(1,:,:)),er);
colormap(jet);
set(h,’LineStyle’,’none’);
view(2);
Please help me solve this problem.
Thank youHello,
I’m implementing a function in mex file (on GPU) in MALTLAB. But I faced with the following error in MATLAB:
Undefined function ‘dts_cast_with_warning’ for input arguments of type ‘matlab.ui.Figure’.
Error in BPmimo2C (line 98)
figure
Error in test (line 29)
BPmimo2C_mex( Efield, f_par, xyz_par, TX, TY, numT, numR)
Here is where this error occurred (in the "figure" part):
…
…
…
for j = 1:numel(z)
hf(j,:,:) = z(j);
end
figure %************** here is where the error occurred
% figure(1);
er = squeeze(max(image,[],1));
h = surf(squeeze(uf(1,:,:)),squeeze(vf(1,:,:)),er);
colormap(jet);
set(h,’LineStyle’,’none’);
view(2);
Please help me solve this problem.
Thank you Hello,
I’m implementing a function in mex file (on GPU) in MALTLAB. But I faced with the following error in MATLAB:
Undefined function ‘dts_cast_with_warning’ for input arguments of type ‘matlab.ui.Figure’.
Error in BPmimo2C (line 98)
figure
Error in test (line 29)
BPmimo2C_mex( Efield, f_par, xyz_par, TX, TY, numT, numR)
Here is where this error occurred (in the "figure" part):
…
…
…
for j = 1:numel(z)
hf(j,:,:) = z(j);
end
figure %************** here is where the error occurred
% figure(1);
er = squeeze(max(image,[],1));
h = surf(squeeze(uf(1,:,:)),squeeze(vf(1,:,:)),er);
colormap(jet);
set(h,’LineStyle’,’none’);
view(2);
Please help me solve this problem.
Thank you matlab, gpu, figure, mex MATLAB Answers — New Questions
Cannot register Custom Add-on Library
I’ve written a custom add-on library to controll a stepper motor, however I’m having trouble registering it. I’ve both added the path via Set Path and tried running >>addpath(‘C:Users…’), but when I type in >>listArduinoLibraries, the add-on doesn’t show up.
The Current Folder browser looks excactly as shown here (https://de.mathworks.com/help/matlab/supportpkg/register-add-on-library.html), with only the src folder and its content appearing faded.
This is my C++ Header File:
# include "LibraryBase.h"
# include "Stepper.h"
// Command IDs
# define ROTATE_STEPPER 0x01
# define STEPPER_SPEED 0x02
class Stepper_L298N : public LibraryBase
{
private:
Stepper stepper;
public:
Stepper_L298N(MWArduinoClass& a, int stepsPerRevolution, int pin1, int pin2, int pin3, int pin4)
: stepper (stepsPerRevolution, pin1, pin2, pin3, pin4)
{
libName = "Stepper_L298N";
a.registerLibrary(this);
}
public:
void commandHandler(byte cmdID, byte* dataIn, unsigned int payloadSize)
{
switch (cmdID){
case ROTATE_STEPPER:{
int steps;
memcpy(&steps, dataIn, sizeof(int));
stepper.step(steps);
sendResponseMsg(cmdID, 0, 0);
break;
}
case STEPPER_SPEED:{
int speed;
memcpy(&speed, dataIn, sizeof(int));
stepper.setSpeed(speed);
sendResponseMsg(cmdID, 0, 0);
break;
}
default:{
}
}
}
};
The first part of my Add-On Class looks like this:
classdef Stepper_L298N < matlabshared.addon.LibraryBase
properties (Access = protected)
Pins
end
properties (Access = private, Constant = true)
ROTATE_STEPPER = hex2dec(’01’)
STEPPER_SPEED = hex2dec(’02’)
end
properties (Access = protected, Constant = true)
LibraryName = ‘Stepper_L298N’
DependentLibraries = {}
LibraryHeaderFiles = ‘Stepper.h’
CppHeaderFile = fullfile(arduinoio.FilePath(mfilename(‘fullpath’)), ‘src’, ‘Stepper_L298N.h’)
CppClassName = ‘Stepper_L298N’
end
I’ve checked for typos in the file names, but I can’t find any. Any advice what else could be wrong?I’ve written a custom add-on library to controll a stepper motor, however I’m having trouble registering it. I’ve both added the path via Set Path and tried running >>addpath(‘C:Users…’), but when I type in >>listArduinoLibraries, the add-on doesn’t show up.
The Current Folder browser looks excactly as shown here (https://de.mathworks.com/help/matlab/supportpkg/register-add-on-library.html), with only the src folder and its content appearing faded.
This is my C++ Header File:
# include "LibraryBase.h"
# include "Stepper.h"
// Command IDs
# define ROTATE_STEPPER 0x01
# define STEPPER_SPEED 0x02
class Stepper_L298N : public LibraryBase
{
private:
Stepper stepper;
public:
Stepper_L298N(MWArduinoClass& a, int stepsPerRevolution, int pin1, int pin2, int pin3, int pin4)
: stepper (stepsPerRevolution, pin1, pin2, pin3, pin4)
{
libName = "Stepper_L298N";
a.registerLibrary(this);
}
public:
void commandHandler(byte cmdID, byte* dataIn, unsigned int payloadSize)
{
switch (cmdID){
case ROTATE_STEPPER:{
int steps;
memcpy(&steps, dataIn, sizeof(int));
stepper.step(steps);
sendResponseMsg(cmdID, 0, 0);
break;
}
case STEPPER_SPEED:{
int speed;
memcpy(&speed, dataIn, sizeof(int));
stepper.setSpeed(speed);
sendResponseMsg(cmdID, 0, 0);
break;
}
default:{
}
}
}
};
The first part of my Add-On Class looks like this:
classdef Stepper_L298N < matlabshared.addon.LibraryBase
properties (Access = protected)
Pins
end
properties (Access = private, Constant = true)
ROTATE_STEPPER = hex2dec(’01’)
STEPPER_SPEED = hex2dec(’02’)
end
properties (Access = protected, Constant = true)
LibraryName = ‘Stepper_L298N’
DependentLibraries = {}
LibraryHeaderFiles = ‘Stepper.h’
CppHeaderFile = fullfile(arduinoio.FilePath(mfilename(‘fullpath’)), ‘src’, ‘Stepper_L298N.h’)
CppClassName = ‘Stepper_L298N’
end
I’ve checked for typos in the file names, but I can’t find any. Any advice what else could be wrong? I’ve written a custom add-on library to controll a stepper motor, however I’m having trouble registering it. I’ve both added the path via Set Path and tried running >>addpath(‘C:Users…’), but when I type in >>listArduinoLibraries, the add-on doesn’t show up.
The Current Folder browser looks excactly as shown here (https://de.mathworks.com/help/matlab/supportpkg/register-add-on-library.html), with only the src folder and its content appearing faded.
This is my C++ Header File:
# include "LibraryBase.h"
# include "Stepper.h"
// Command IDs
# define ROTATE_STEPPER 0x01
# define STEPPER_SPEED 0x02
class Stepper_L298N : public LibraryBase
{
private:
Stepper stepper;
public:
Stepper_L298N(MWArduinoClass& a, int stepsPerRevolution, int pin1, int pin2, int pin3, int pin4)
: stepper (stepsPerRevolution, pin1, pin2, pin3, pin4)
{
libName = "Stepper_L298N";
a.registerLibrary(this);
}
public:
void commandHandler(byte cmdID, byte* dataIn, unsigned int payloadSize)
{
switch (cmdID){
case ROTATE_STEPPER:{
int steps;
memcpy(&steps, dataIn, sizeof(int));
stepper.step(steps);
sendResponseMsg(cmdID, 0, 0);
break;
}
case STEPPER_SPEED:{
int speed;
memcpy(&speed, dataIn, sizeof(int));
stepper.setSpeed(speed);
sendResponseMsg(cmdID, 0, 0);
break;
}
default:{
}
}
}
};
The first part of my Add-On Class looks like this:
classdef Stepper_L298N < matlabshared.addon.LibraryBase
properties (Access = protected)
Pins
end
properties (Access = private, Constant = true)
ROTATE_STEPPER = hex2dec(’01’)
STEPPER_SPEED = hex2dec(’02’)
end
properties (Access = protected, Constant = true)
LibraryName = ‘Stepper_L298N’
DependentLibraries = {}
LibraryHeaderFiles = ‘Stepper.h’
CppHeaderFile = fullfile(arduinoio.FilePath(mfilename(‘fullpath’)), ‘src’, ‘Stepper_L298N.h’)
CppClassName = ‘Stepper_L298N’
end
I’ve checked for typos in the file names, but I can’t find any. Any advice what else could be wrong? arduino, add-on MATLAB Answers — New Questions
Where do I install third-pary libraries?
I’ve written a custom add-on library, that includes the ‘Stepper.h’ library from Arduino. I have definitely downloaded and installed the Arduino library and can access it from the Arduino IDE just fine. However, when I try running my code in Matlab, I get the following error:
"The Arduino source ‘Stepper.h’ for libraries ‘StepperL298N/Stepper_L298N’ cannot be found. Install the third party library source first and try again."
I know where the library is and have added the path manually, but will still get he same error. When I enter >>fullfile(arduinoio.CLIRoot, ‘user’,’libraries’) to find out where to move the library so that Matlab can find it, I get the following error:
"Unable to resolve the name ‘arduinoio.CLIRoot’"
Can someone tell me how to resolve this?I’ve written a custom add-on library, that includes the ‘Stepper.h’ library from Arduino. I have definitely downloaded and installed the Arduino library and can access it from the Arduino IDE just fine. However, when I try running my code in Matlab, I get the following error:
"The Arduino source ‘Stepper.h’ for libraries ‘StepperL298N/Stepper_L298N’ cannot be found. Install the third party library source first and try again."
I know where the library is and have added the path manually, but will still get he same error. When I enter >>fullfile(arduinoio.CLIRoot, ‘user’,’libraries’) to find out where to move the library so that Matlab can find it, I get the following error:
"Unable to resolve the name ‘arduinoio.CLIRoot’"
Can someone tell me how to resolve this? I’ve written a custom add-on library, that includes the ‘Stepper.h’ library from Arduino. I have definitely downloaded and installed the Arduino library and can access it from the Arduino IDE just fine. However, when I try running my code in Matlab, I get the following error:
"The Arduino source ‘Stepper.h’ for libraries ‘StepperL298N/Stepper_L298N’ cannot be found. Install the third party library source first and try again."
I know where the library is and have added the path manually, but will still get he same error. When I enter >>fullfile(arduinoio.CLIRoot, ‘user’,’libraries’) to find out where to move the library so that Matlab can find it, I get the following error:
"Unable to resolve the name ‘arduinoio.CLIRoot’"
Can someone tell me how to resolve this? custom add-on library, third-party libraries MATLAB Answers — New Questions
Based on the surf algorithm, I am stitching three images with overlapping regions.
Based on the surf algorithm, I am stitching three images with overlapping regions. I have code that successfully stitches img1 and img2 into result1, and img2 and img3 into result2. However, when I attempt to stitch result1 and result2 together, issues arise. How should I proceed?
基于surf算法,拼接三张具有重叠区域的图像。我有拼接两张的代码,问题是三张图片img1,img2,img3,img1和img2有重叠区域,img2和img3有重叠区域。img1和img2拼接没有问题,结果是result1,img2和img3拼接没有问题,结果是result2,但将result1和result2拼接时却出现了问题,我该怎么办Based on the surf algorithm, I am stitching three images with overlapping regions. I have code that successfully stitches img1 and img2 into result1, and img2 and img3 into result2. However, when I attempt to stitch result1 and result2 together, issues arise. How should I proceed?
基于surf算法,拼接三张具有重叠区域的图像。我有拼接两张的代码,问题是三张图片img1,img2,img3,img1和img2有重叠区域,img2和img3有重叠区域。img1和img2拼接没有问题,结果是result1,img2和img3拼接没有问题,结果是result2,但将result1和result2拼接时却出现了问题,我该怎么办 Based on the surf algorithm, I am stitching three images with overlapping regions. I have code that successfully stitches img1 and img2 into result1, and img2 and img3 into result2. However, when I attempt to stitch result1 and result2 together, issues arise. How should I proceed?
基于surf算法,拼接三张具有重叠区域的图像。我有拼接两张的代码,问题是三张图片img1,img2,img3,img1和img2有重叠区域,img2和img3有重叠区域。img1和img2拼接没有问题,结果是result1,img2和img3拼接没有问题,结果是result2,但将result1和result2拼接时却出现了问题,我该怎么办 surf, image stiching MATLAB Answers — New Questions
Rectify image with known coordinates
I have calibration images from four cameras in a 1×4 array. For simplicity, I’m showing the processing for just one camera. The image shows a calibration plate that contains black dots at a know separation.
The image is in pixels. I already post processes the image and obtain a rectification mapping function image coordinates to world coordinates. I input the location of known location in the image in image coordinates and the coordinates of these points in the real world. The output is the function that can take any point in image coordinates and convert it to real world coordinates.
I can plot the points in real world coordinates using the ‘scatter function’ (as in the figure below) but I’m having problems rectifying the whole image. I have no idea how to reshape the image with the new real world coordinates.
Here’s the data and code (data was a bit over 5MB).
clear
clc
close all
% I = points in image coordinates
% W = same points as in I but in real world coordinates
% calImg = Raw image in image coordinates
load("calImg.mat")
rectify_quad = cell(length(calImg),1); imagePoints2 = rectify_quad;
% CALIBRATION: compute the image rectification function for this camera
% from the world coords and image coords of the calibration dots (using
% a quadratic transformation: order = 2)
trans_order = 2;
rectify_quad{1} = calibrate_camera(I,W,trans_order);
imagePoints2{1} = rectify_quad{1}(I);
figure(1)
subplot(121)
imagesc(calImg); hold on
colormap(gray)
scatter(I(:,1), I(:,2), ‘r’, ‘LineWidth’,1)
axis equal
xlabel(‘pixel’)
ylabel(‘pixel’)
title(‘Image and detected points (Image coord)’)
subplot(122)
% I want to plot the rectified image in world coordinates similar to subplot (121)
scatter(imagePoints2{1}(:,1),imagePoints2{1}(:,2), ‘r’, ‘LineWidth’,1);
axis equal
xlabel(‘meters’)
ylabel(‘meters’)
title(‘detected points (real world coord)’)
function rectify = calibrate_camera(I,W,order)
% calculate the transformation function to convert image coordinates to
% world (physical) coordinates, including calibration (converting pixels to
% meters), undistortion, and rectification
%
% rectify: function handle to map image coordinates to world coordinates
% I: set of known calibration points in image coordinates (n x 2 vector) [px]
% W: set of known calibration points in world coordinates (n x 2 vector) [m]
% order: 1 for linear transformation (corrects for camera viewing angle but not lens distortion),
% 2 for quadratic transformation (corrects for camera viewing angle and lens distortion)
%
% references: Fujita et al 1998 (Water Res.), Creutin et al 2003 (J. Hydrol.)
%
% to use function handle: points_m = rectify(points_px)
% points_px: set of points in image coordinates (m x 2 vector) [px]
% points_m: set of points converted to world coordinates (m x 2 vector) [px]
% find transformation coefficients
if order == 2
A = [I.^2, I, ones(size(I,1),1), -I(:,1).^2.*W(:,1), -I(:,2).^2.*W(:,1), -I(:,1).*W(:,1), -I(:,2).*W(:,1), zeros(size(I,1),5);
zeros(size(I,1),5), -I(:,1).^2.*W(:,2), -I(:,2).^2.*W(:,2), -I(:,1).*W(:,2), -I(:,2).*W(:,2), I.^2, I, ones(size(I,1),1)];
else
A = [I, ones(size(I,1),1), -I(:,1).*W(:,1), -I(:,2).*W(:,1), zeros(size(I,1),3);
zeros(size(I,1),3), -I(:,1).*W(:,2), -I(:,2).*W(:,2), I, ones(size(I,1),1)];
end
Z = [W(:,1); W(:,2)];
B = (A’*A)^-1*A’*Z;
% function to map image coords to world coords
if order == 2
rectify = @(I) [(B(1)*I(:,1).^2 + B(2)*I(:,2).^2 + B(3)*I(:,1) + B(4)*I(:,2) + B(5))./ …
(B(6)*I(:,1).^2 + B(7)*I(:,2).^2 + B(8)*I(:,1) + B(9)*I(:,2) + 1), …
(B(10)*I(:,1).^2 + B(11)*I(:,2).^2 + B(12)*I(:,1) + B(13)*I(:,2) + B(14))./ …
(B(6)*I(:,1).^2 + B(7)*I(:,2).^2 + B(8)*I(:,1) + B(9)*I(:,2) + 1)];
else
rectify = @(I) [(B(1)*I(:,1) + B(2)*I(:,2) + B(3))./ …
(B(4)*I(:,1) + B(5)*I(:,2) + 1), …
(B(6)*I(:,1) + B(7)*I(:,2) + B(8))./ …
(B(4)*I(:,1) + B(5)*I(:,2) + 1)];
end
end
And here is an figure as reference. I want to rectify the raw image (convert it to real world coordinates) and plot it like in subplot(121)I have calibration images from four cameras in a 1×4 array. For simplicity, I’m showing the processing for just one camera. The image shows a calibration plate that contains black dots at a know separation.
The image is in pixels. I already post processes the image and obtain a rectification mapping function image coordinates to world coordinates. I input the location of known location in the image in image coordinates and the coordinates of these points in the real world. The output is the function that can take any point in image coordinates and convert it to real world coordinates.
I can plot the points in real world coordinates using the ‘scatter function’ (as in the figure below) but I’m having problems rectifying the whole image. I have no idea how to reshape the image with the new real world coordinates.
Here’s the data and code (data was a bit over 5MB).
clear
clc
close all
% I = points in image coordinates
% W = same points as in I but in real world coordinates
% calImg = Raw image in image coordinates
load("calImg.mat")
rectify_quad = cell(length(calImg),1); imagePoints2 = rectify_quad;
% CALIBRATION: compute the image rectification function for this camera
% from the world coords and image coords of the calibration dots (using
% a quadratic transformation: order = 2)
trans_order = 2;
rectify_quad{1} = calibrate_camera(I,W,trans_order);
imagePoints2{1} = rectify_quad{1}(I);
figure(1)
subplot(121)
imagesc(calImg); hold on
colormap(gray)
scatter(I(:,1), I(:,2), ‘r’, ‘LineWidth’,1)
axis equal
xlabel(‘pixel’)
ylabel(‘pixel’)
title(‘Image and detected points (Image coord)’)
subplot(122)
% I want to plot the rectified image in world coordinates similar to subplot (121)
scatter(imagePoints2{1}(:,1),imagePoints2{1}(:,2), ‘r’, ‘LineWidth’,1);
axis equal
xlabel(‘meters’)
ylabel(‘meters’)
title(‘detected points (real world coord)’)
function rectify = calibrate_camera(I,W,order)
% calculate the transformation function to convert image coordinates to
% world (physical) coordinates, including calibration (converting pixels to
% meters), undistortion, and rectification
%
% rectify: function handle to map image coordinates to world coordinates
% I: set of known calibration points in image coordinates (n x 2 vector) [px]
% W: set of known calibration points in world coordinates (n x 2 vector) [m]
% order: 1 for linear transformation (corrects for camera viewing angle but not lens distortion),
% 2 for quadratic transformation (corrects for camera viewing angle and lens distortion)
%
% references: Fujita et al 1998 (Water Res.), Creutin et al 2003 (J. Hydrol.)
%
% to use function handle: points_m = rectify(points_px)
% points_px: set of points in image coordinates (m x 2 vector) [px]
% points_m: set of points converted to world coordinates (m x 2 vector) [px]
% find transformation coefficients
if order == 2
A = [I.^2, I, ones(size(I,1),1), -I(:,1).^2.*W(:,1), -I(:,2).^2.*W(:,1), -I(:,1).*W(:,1), -I(:,2).*W(:,1), zeros(size(I,1),5);
zeros(size(I,1),5), -I(:,1).^2.*W(:,2), -I(:,2).^2.*W(:,2), -I(:,1).*W(:,2), -I(:,2).*W(:,2), I.^2, I, ones(size(I,1),1)];
else
A = [I, ones(size(I,1),1), -I(:,1).*W(:,1), -I(:,2).*W(:,1), zeros(size(I,1),3);
zeros(size(I,1),3), -I(:,1).*W(:,2), -I(:,2).*W(:,2), I, ones(size(I,1),1)];
end
Z = [W(:,1); W(:,2)];
B = (A’*A)^-1*A’*Z;
% function to map image coords to world coords
if order == 2
rectify = @(I) [(B(1)*I(:,1).^2 + B(2)*I(:,2).^2 + B(3)*I(:,1) + B(4)*I(:,2) + B(5))./ …
(B(6)*I(:,1).^2 + B(7)*I(:,2).^2 + B(8)*I(:,1) + B(9)*I(:,2) + 1), …
(B(10)*I(:,1).^2 + B(11)*I(:,2).^2 + B(12)*I(:,1) + B(13)*I(:,2) + B(14))./ …
(B(6)*I(:,1).^2 + B(7)*I(:,2).^2 + B(8)*I(:,1) + B(9)*I(:,2) + 1)];
else
rectify = @(I) [(B(1)*I(:,1) + B(2)*I(:,2) + B(3))./ …
(B(4)*I(:,1) + B(5)*I(:,2) + 1), …
(B(6)*I(:,1) + B(7)*I(:,2) + B(8))./ …
(B(4)*I(:,1) + B(5)*I(:,2) + 1)];
end
end
And here is an figure as reference. I want to rectify the raw image (convert it to real world coordinates) and plot it like in subplot(121) I have calibration images from four cameras in a 1×4 array. For simplicity, I’m showing the processing for just one camera. The image shows a calibration plate that contains black dots at a know separation.
The image is in pixels. I already post processes the image and obtain a rectification mapping function image coordinates to world coordinates. I input the location of known location in the image in image coordinates and the coordinates of these points in the real world. The output is the function that can take any point in image coordinates and convert it to real world coordinates.
I can plot the points in real world coordinates using the ‘scatter function’ (as in the figure below) but I’m having problems rectifying the whole image. I have no idea how to reshape the image with the new real world coordinates.
Here’s the data and code (data was a bit over 5MB).
clear
clc
close all
% I = points in image coordinates
% W = same points as in I but in real world coordinates
% calImg = Raw image in image coordinates
load("calImg.mat")
rectify_quad = cell(length(calImg),1); imagePoints2 = rectify_quad;
% CALIBRATION: compute the image rectification function for this camera
% from the world coords and image coords of the calibration dots (using
% a quadratic transformation: order = 2)
trans_order = 2;
rectify_quad{1} = calibrate_camera(I,W,trans_order);
imagePoints2{1} = rectify_quad{1}(I);
figure(1)
subplot(121)
imagesc(calImg); hold on
colormap(gray)
scatter(I(:,1), I(:,2), ‘r’, ‘LineWidth’,1)
axis equal
xlabel(‘pixel’)
ylabel(‘pixel’)
title(‘Image and detected points (Image coord)’)
subplot(122)
% I want to plot the rectified image in world coordinates similar to subplot (121)
scatter(imagePoints2{1}(:,1),imagePoints2{1}(:,2), ‘r’, ‘LineWidth’,1);
axis equal
xlabel(‘meters’)
ylabel(‘meters’)
title(‘detected points (real world coord)’)
function rectify = calibrate_camera(I,W,order)
% calculate the transformation function to convert image coordinates to
% world (physical) coordinates, including calibration (converting pixels to
% meters), undistortion, and rectification
%
% rectify: function handle to map image coordinates to world coordinates
% I: set of known calibration points in image coordinates (n x 2 vector) [px]
% W: set of known calibration points in world coordinates (n x 2 vector) [m]
% order: 1 for linear transformation (corrects for camera viewing angle but not lens distortion),
% 2 for quadratic transformation (corrects for camera viewing angle and lens distortion)
%
% references: Fujita et al 1998 (Water Res.), Creutin et al 2003 (J. Hydrol.)
%
% to use function handle: points_m = rectify(points_px)
% points_px: set of points in image coordinates (m x 2 vector) [px]
% points_m: set of points converted to world coordinates (m x 2 vector) [px]
% find transformation coefficients
if order == 2
A = [I.^2, I, ones(size(I,1),1), -I(:,1).^2.*W(:,1), -I(:,2).^2.*W(:,1), -I(:,1).*W(:,1), -I(:,2).*W(:,1), zeros(size(I,1),5);
zeros(size(I,1),5), -I(:,1).^2.*W(:,2), -I(:,2).^2.*W(:,2), -I(:,1).*W(:,2), -I(:,2).*W(:,2), I.^2, I, ones(size(I,1),1)];
else
A = [I, ones(size(I,1),1), -I(:,1).*W(:,1), -I(:,2).*W(:,1), zeros(size(I,1),3);
zeros(size(I,1),3), -I(:,1).*W(:,2), -I(:,2).*W(:,2), I, ones(size(I,1),1)];
end
Z = [W(:,1); W(:,2)];
B = (A’*A)^-1*A’*Z;
% function to map image coords to world coords
if order == 2
rectify = @(I) [(B(1)*I(:,1).^2 + B(2)*I(:,2).^2 + B(3)*I(:,1) + B(4)*I(:,2) + B(5))./ …
(B(6)*I(:,1).^2 + B(7)*I(:,2).^2 + B(8)*I(:,1) + B(9)*I(:,2) + 1), …
(B(10)*I(:,1).^2 + B(11)*I(:,2).^2 + B(12)*I(:,1) + B(13)*I(:,2) + B(14))./ …
(B(6)*I(:,1).^2 + B(7)*I(:,2).^2 + B(8)*I(:,1) + B(9)*I(:,2) + 1)];
else
rectify = @(I) [(B(1)*I(:,1) + B(2)*I(:,2) + B(3))./ …
(B(4)*I(:,1) + B(5)*I(:,2) + 1), …
(B(6)*I(:,1) + B(7)*I(:,2) + B(8))./ …
(B(4)*I(:,1) + B(5)*I(:,2) + 1)];
end
end
And here is an figure as reference. I want to rectify the raw image (convert it to real world coordinates) and plot it like in subplot(121) image processing, image analysis, orthorectification MATLAB Answers — New Questions
如何优化这段代码
clear,clc,close all
n=80; AB=400; M=100000;
prob=optimproblem;
x=optimvar(‘x’,3,n,’LowerBound’,zeros);
flagx=optimvar(‘flagx’,1,n,’Type’,’integer’,’LowerBound’,0,’UpperBound’,1);
con7=sum(x(3,:)./cos(x(1,:)))<=200; %未考虑EF遮蔽光线
con2=[];
for i=1:n
con2=[con2;x(1,i)<=pi/2;x(2,i)<=200;x(3,i)/cos(x(1,i))<=2.5];
end
con8=[];
for i=1:n-1
con8=[con8;sum(x(3,1:i))==x(2,i+1)];
end
p=100;
k=1./tan(2*x(1,:));
b=(x(2,:)+x(3,:)./cos(x(1,:)))./tan(2*x(1,:))+x(3,:).*tan(x(1,:));
b1=x(2,:)./tan(2*x(1,:));
[g, theta]=reflect_point(k,b,x,x(2,:),n);
[g1, theta1]=reflect_point(k,b1,x,x(2,:),n);
con4=[]; con5=[]; con6=[];
for i=1:n
con4=[con4;g(i)>=-5*flagx(i)+M*(flagx(i)-1)];
con5=[con5;g1(i)<=5*flagx(i)-M*(flagx(i)-1)];
con6=[con6;x(1,i)>=1/M];
end
con1=theta>=pi/2-x(1,:)*2;
con3=theta1>=pi/2-x(1,:)*2;
prob.Constraints.con1=con1;
prob.Constraints.con2=con2;
prob.Constraints.con3=con3;
prob.Constraints.con4=con4;
prob.Constraints.con5=con5;
prob.Constraints.con6=con6;
prob.Constraints.con7=con7;
prob.Constraints.con8=con8;
prob.Objective=-sum(flagx);
A(1,1:n)=pi/2;
A(2:3,:)=ones;
x00.x=A;
x00.flagx=ones(1,n);
[sol, fval, flag, out] = solve(prob,x00);
x=sol.x;
k=1./tan(2*x(1,:));
bb(1,:)=(x(2,:)+x(3,:)./cos(x(1,:)))./tan(2*x(1,:))+x(3,:).*sin(x(1,:));
bb(2,:)=x(2,:)./tan(2*x(1,:));
x01=p*k-sqrt(2*p.*bb(1,:)-200*p+(p*k).^2);
y01=(x01.^2)./(2*p)+100;
[gg(1,:), thetaa(1,:)]=reflect_point(k,bb(1,:),x,x(2,:),n);
[gg(2,:), thetaa(2,:)]=reflect_point(k,bb(2,:),x,x(2,:),n);
thetaa(3,:)=pi/2-x(1,:)*2;
function [g, theta] = reflect_point(k,b,x,d,n)
p=100;
x0=p*k-sqrt(2*p.*b-200*p+(p*k).^2);
y0=(x0.^2)./(2*p)+100;
theta=atan(-p./x0);
g=tan(2*theta+2*x(1,:)).*y0+x0;
endclear,clc,close all
n=80; AB=400; M=100000;
prob=optimproblem;
x=optimvar(‘x’,3,n,’LowerBound’,zeros);
flagx=optimvar(‘flagx’,1,n,’Type’,’integer’,’LowerBound’,0,’UpperBound’,1);
con7=sum(x(3,:)./cos(x(1,:)))<=200; %未考虑EF遮蔽光线
con2=[];
for i=1:n
con2=[con2;x(1,i)<=pi/2;x(2,i)<=200;x(3,i)/cos(x(1,i))<=2.5];
end
con8=[];
for i=1:n-1
con8=[con8;sum(x(3,1:i))==x(2,i+1)];
end
p=100;
k=1./tan(2*x(1,:));
b=(x(2,:)+x(3,:)./cos(x(1,:)))./tan(2*x(1,:))+x(3,:).*tan(x(1,:));
b1=x(2,:)./tan(2*x(1,:));
[g, theta]=reflect_point(k,b,x,x(2,:),n);
[g1, theta1]=reflect_point(k,b1,x,x(2,:),n);
con4=[]; con5=[]; con6=[];
for i=1:n
con4=[con4;g(i)>=-5*flagx(i)+M*(flagx(i)-1)];
con5=[con5;g1(i)<=5*flagx(i)-M*(flagx(i)-1)];
con6=[con6;x(1,i)>=1/M];
end
con1=theta>=pi/2-x(1,:)*2;
con3=theta1>=pi/2-x(1,:)*2;
prob.Constraints.con1=con1;
prob.Constraints.con2=con2;
prob.Constraints.con3=con3;
prob.Constraints.con4=con4;
prob.Constraints.con5=con5;
prob.Constraints.con6=con6;
prob.Constraints.con7=con7;
prob.Constraints.con8=con8;
prob.Objective=-sum(flagx);
A(1,1:n)=pi/2;
A(2:3,:)=ones;
x00.x=A;
x00.flagx=ones(1,n);
[sol, fval, flag, out] = solve(prob,x00);
x=sol.x;
k=1./tan(2*x(1,:));
bb(1,:)=(x(2,:)+x(3,:)./cos(x(1,:)))./tan(2*x(1,:))+x(3,:).*sin(x(1,:));
bb(2,:)=x(2,:)./tan(2*x(1,:));
x01=p*k-sqrt(2*p.*bb(1,:)-200*p+(p*k).^2);
y01=(x01.^2)./(2*p)+100;
[gg(1,:), thetaa(1,:)]=reflect_point(k,bb(1,:),x,x(2,:),n);
[gg(2,:), thetaa(2,:)]=reflect_point(k,bb(2,:),x,x(2,:),n);
thetaa(3,:)=pi/2-x(1,:)*2;
function [g, theta] = reflect_point(k,b,x,d,n)
p=100;
x0=p*k-sqrt(2*p.*b-200*p+(p*k).^2);
y0=(x0.^2)./(2*p)+100;
theta=atan(-p./x0);
g=tan(2*theta+2*x(1,:)).*y0+x0;
end clear,clc,close all
n=80; AB=400; M=100000;
prob=optimproblem;
x=optimvar(‘x’,3,n,’LowerBound’,zeros);
flagx=optimvar(‘flagx’,1,n,’Type’,’integer’,’LowerBound’,0,’UpperBound’,1);
con7=sum(x(3,:)./cos(x(1,:)))<=200; %未考虑EF遮蔽光线
con2=[];
for i=1:n
con2=[con2;x(1,i)<=pi/2;x(2,i)<=200;x(3,i)/cos(x(1,i))<=2.5];
end
con8=[];
for i=1:n-1
con8=[con8;sum(x(3,1:i))==x(2,i+1)];
end
p=100;
k=1./tan(2*x(1,:));
b=(x(2,:)+x(3,:)./cos(x(1,:)))./tan(2*x(1,:))+x(3,:).*tan(x(1,:));
b1=x(2,:)./tan(2*x(1,:));
[g, theta]=reflect_point(k,b,x,x(2,:),n);
[g1, theta1]=reflect_point(k,b1,x,x(2,:),n);
con4=[]; con5=[]; con6=[];
for i=1:n
con4=[con4;g(i)>=-5*flagx(i)+M*(flagx(i)-1)];
con5=[con5;g1(i)<=5*flagx(i)-M*(flagx(i)-1)];
con6=[con6;x(1,i)>=1/M];
end
con1=theta>=pi/2-x(1,:)*2;
con3=theta1>=pi/2-x(1,:)*2;
prob.Constraints.con1=con1;
prob.Constraints.con2=con2;
prob.Constraints.con3=con3;
prob.Constraints.con4=con4;
prob.Constraints.con5=con5;
prob.Constraints.con6=con6;
prob.Constraints.con7=con7;
prob.Constraints.con8=con8;
prob.Objective=-sum(flagx);
A(1,1:n)=pi/2;
A(2:3,:)=ones;
x00.x=A;
x00.flagx=ones(1,n);
[sol, fval, flag, out] = solve(prob,x00);
x=sol.x;
k=1./tan(2*x(1,:));
bb(1,:)=(x(2,:)+x(3,:)./cos(x(1,:)))./tan(2*x(1,:))+x(3,:).*sin(x(1,:));
bb(2,:)=x(2,:)./tan(2*x(1,:));
x01=p*k-sqrt(2*p.*bb(1,:)-200*p+(p*k).^2);
y01=(x01.^2)./(2*p)+100;
[gg(1,:), thetaa(1,:)]=reflect_point(k,bb(1,:),x,x(2,:),n);
[gg(2,:), thetaa(2,:)]=reflect_point(k,bb(2,:),x,x(2,:),n);
thetaa(3,:)=pi/2-x(1,:)*2;
function [g, theta] = reflect_point(k,b,x,d,n)
p=100;
x0=p*k-sqrt(2*p.*b-200*p+(p*k).^2);
y0=(x0.^2)./(2*p)+100;
theta=atan(-p./x0);
g=tan(2*theta+2*x(1,:)).*y0+x0;
end 优化问题 MATLAB Answers — New Questions
fsolve error: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
I’m tring to run the following set of code:
%% SW Model: Primary VR
dfreq_SW_vr = -6e-3;
% MMS
gamma_SW = 0.0001*pi : 0.0001 : 0.415*pi;
x0_SW = [0, 0];
options = optimoptions(@fsolve,’StepTolerance’,1e-15);
for ct = 1:numel(gamma_SW)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
x0_SW = [ x_SW(end,1)+0.001 , x_SW(end,2)+0.003]; % Update IC
end
figure(8)
% MMS (Stable)
plot(x_SW(1:10,1), 2*x_SW(1:10,2),’Color’,[.7 .7 .7],’LineWidth’,2.5)
hold on; grid on;
%% Function File (SW VR)
function Eqn_SW = bicycle_SW(x_SW, gamma_SW)
global w b g1 g2 g3 g4 dfreq_SW_vr nu f1b f2b zet_0_0 eta_0_0 zet_1_0 eta_1_0 zet_2_0 eta_2_0 zet_3_0 eta_3_0
% Note: Eqn(1) = Real, Eqn(2) = Imag
% Note: x_–(1) = d, x_–(2) = a
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 + ((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) + ((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Eqn_SW(2) = (-1./2).*b.*w(1).*x_SW(2).*g2 + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*sin(gamma_SW) + ((1./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*sin(gamma_SW);
end
But I get the following error when I run it:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in untitled3>bicycle_SW (line 91)
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 +
f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 +
((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) +
((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Error in untitled3>@(x_SW)bicycle_SW(x_SW,gamma_SW(ct)) (line 13)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
Not sure what I’m doing wrong… Any help would be much appreciated.I’m tring to run the following set of code:
%% SW Model: Primary VR
dfreq_SW_vr = -6e-3;
% MMS
gamma_SW = 0.0001*pi : 0.0001 : 0.415*pi;
x0_SW = [0, 0];
options = optimoptions(@fsolve,’StepTolerance’,1e-15);
for ct = 1:numel(gamma_SW)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
x0_SW = [ x_SW(end,1)+0.001 , x_SW(end,2)+0.003]; % Update IC
end
figure(8)
% MMS (Stable)
plot(x_SW(1:10,1), 2*x_SW(1:10,2),’Color’,[.7 .7 .7],’LineWidth’,2.5)
hold on; grid on;
%% Function File (SW VR)
function Eqn_SW = bicycle_SW(x_SW, gamma_SW)
global w b g1 g2 g3 g4 dfreq_SW_vr nu f1b f2b zet_0_0 eta_0_0 zet_1_0 eta_1_0 zet_2_0 eta_2_0 zet_3_0 eta_3_0
% Note: Eqn(1) = Real, Eqn(2) = Imag
% Note: x_–(1) = d, x_–(2) = a
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 + ((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) + ((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Eqn_SW(2) = (-1./2).*b.*w(1).*x_SW(2).*g2 + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*sin(gamma_SW) + ((1./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*sin(gamma_SW);
end
But I get the following error when I run it:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in untitled3>bicycle_SW (line 91)
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 +
f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 +
((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) +
((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Error in untitled3>@(x_SW)bicycle_SW(x_SW,gamma_SW(ct)) (line 13)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
Not sure what I’m doing wrong… Any help would be much appreciated. I’m tring to run the following set of code:
%% SW Model: Primary VR
dfreq_SW_vr = -6e-3;
% MMS
gamma_SW = 0.0001*pi : 0.0001 : 0.415*pi;
x0_SW = [0, 0];
options = optimoptions(@fsolve,’StepTolerance’,1e-15);
for ct = 1:numel(gamma_SW)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
x0_SW = [ x_SW(end,1)+0.001 , x_SW(end,2)+0.003]; % Update IC
end
figure(8)
% MMS (Stable)
plot(x_SW(1:10,1), 2*x_SW(1:10,2),’Color’,[.7 .7 .7],’LineWidth’,2.5)
hold on; grid on;
%% Function File (SW VR)
function Eqn_SW = bicycle_SW(x_SW, gamma_SW)
global w b g1 g2 g3 g4 dfreq_SW_vr nu f1b f2b zet_0_0 eta_0_0 zet_1_0 eta_1_0 zet_2_0 eta_2_0 zet_3_0 eta_3_0
% Note: Eqn(1) = Real, Eqn(2) = Imag
% Note: x_–(1) = d, x_–(2) = a
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 + ((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) + ((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Eqn_SW(2) = (-1./2).*b.*w(1).*x_SW(2).*g2 + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 + f2b.*eta_0_0).*g1.*sin(gamma_SW) + ((1./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*sin(gamma_SW);
end
But I get the following error when I run it:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in untitled3>bicycle_SW (line 91)
Eqn_SW(1) = (2.*x_SW(2).*dfreq_SW_vr.*w(1).*g2) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_0_0 +
f2b.*eta_0_0).*g1.*cos(gamma_SW) + ((1./4).*x_SW(1).*nu).*(f1b.*zet_1_0 + f2b.*eta_1_0).*x_SW(2).*g2 +
((3./16).*x_SW(1).*nu).*(f1b.*zet_2_0 + f2b.*eta_2_0).*(x_SW(2).^2).*g3.*cos(gamma_SW) +
((3./16).*x_SW(1).*nu).*(f1b.*zet_3_0 + f2b.*eta_3_0).*(x_SW(2).^3).*g4;
Error in untitled3>@(x_SW)bicycle_SW(x_SW,gamma_SW(ct)) (line 13)
x_SW(ct,:) = fsolve( @(x_SW)bicycle_SW(x_SW, gamma_SW(ct)), x0_SW, options);
Not sure what I’m doing wrong… Any help would be much appreciated. fsolve, compatible, indices MATLAB Answers — New Questions
Why is navigation tool menu non-responsive in AppDesigner app?
Hello,
I have an app I created in AppDesigner. It has 3 axes in the window. I plot images using pcolor in two of these axes. The images are not large, and on the order of 150×150 pixels each. When I am in AppDesigner and launch the app for testing, quite often the navigation buttons on the upper right pop-up menu in each axes becomes unresponsive to my clicks to try to enable the zoom in tool. Even other clicks like "home" button fails to respond for a long time. Sometimes it never responds. I am wondering what might be causing this poor behavior. Nothing is computing in Matlab in the background when this is happening.Hello,
I have an app I created in AppDesigner. It has 3 axes in the window. I plot images using pcolor in two of these axes. The images are not large, and on the order of 150×150 pixels each. When I am in AppDesigner and launch the app for testing, quite often the navigation buttons on the upper right pop-up menu in each axes becomes unresponsive to my clicks to try to enable the zoom in tool. Even other clicks like "home" button fails to respond for a long time. Sometimes it never responds. I am wondering what might be causing this poor behavior. Nothing is computing in Matlab in the background when this is happening. Hello,
I have an app I created in AppDesigner. It has 3 axes in the window. I plot images using pcolor in two of these axes. The images are not large, and on the order of 150×150 pixels each. When I am in AppDesigner and launch the app for testing, quite often the navigation buttons on the upper right pop-up menu in each axes becomes unresponsive to my clicks to try to enable the zoom in tool. Even other clicks like "home" button fails to respond for a long time. Sometimes it never responds. I am wondering what might be causing this poor behavior. Nothing is computing in Matlab in the background when this is happening. appdesigner, navigation tool bar, axes MATLAB Answers — New Questions
implementing a two-loop PI controller for both current and voltage – buck converter
I’m working on a project involving a DC-DC buck converter for a battery system in MATLAB Simulink. I need help implementing a two-loop PI controller for both current and voltage. Can someone guide me on how to set this up?I’m working on a project involving a DC-DC buck converter for a battery system in MATLAB Simulink. I need help implementing a two-loop PI controller for both current and voltage. Can someone guide me on how to set this up? I’m working on a project involving a DC-DC buck converter for a battery system in MATLAB Simulink. I need help implementing a two-loop PI controller for both current and voltage. Can someone guide me on how to set this up? buck converter, two loop pi controller, pi controller MATLAB Answers — New Questions
Is there a way to check answers using rand in MATLAB Grader?
I am using MATLAB Grader to check students’ work. Many basic problems ask them to create particular arrays using rand or randi. Is there a way to check if their answer is a possible correct answer?
For example, a problem could ask them to generate a vector v1 of 20 random integers between -4 and 2.
v1 = randi([-4,2],1, 20);
But if I use the assessVariableEqual function to check their answer, it won’t work because their answer contains randomized values. I’d like to be able to check the min, max, and length of the result to see that it is within the expected range. Is there a way to do that?I am using MATLAB Grader to check students’ work. Many basic problems ask them to create particular arrays using rand or randi. Is there a way to check if their answer is a possible correct answer?
For example, a problem could ask them to generate a vector v1 of 20 random integers between -4 and 2.
v1 = randi([-4,2],1, 20);
But if I use the assessVariableEqual function to check their answer, it won’t work because their answer contains randomized values. I’d like to be able to check the min, max, and length of the result to see that it is within the expected range. Is there a way to do that? I am using MATLAB Grader to check students’ work. Many basic problems ask them to create particular arrays using rand or randi. Is there a way to check if their answer is a possible correct answer?
For example, a problem could ask them to generate a vector v1 of 20 random integers between -4 and 2.
v1 = randi([-4,2],1, 20);
But if I use the assessVariableEqual function to check their answer, it won’t work because their answer contains randomized values. I’d like to be able to check the min, max, and length of the result to see that it is within the expected range. Is there a way to do that? grader, rand, randi MATLAB Answers — New Questions
Which products should I select ?
When I download and install R2024a i saw alot lot of products ,what should i install as a Mathematics student ?When I download and install R2024a i saw alot lot of products ,what should i install as a Mathematics student ? When I download and install R2024a i saw alot lot of products ,what should i install as a Mathematics student ? mathematics, math, product MATLAB Answers — New Questions
Please help me to sove this problem, thank you so much!
Error in ‘bingwangnibia1/Subsystem/vo’: Initialization commands cannot be evaluated.
Caused by:
PSB option menu block block (mask) does not have a parameter named ‘NonlinearTolerance’Error in ‘bingwangnibia1/Subsystem/vo’: Initialization commands cannot be evaluated.
Caused by:
PSB option menu block block (mask) does not have a parameter named ‘NonlinearTolerance’ Error in ‘bingwangnibia1/Subsystem/vo’: Initialization commands cannot be evaluated.
Caused by:
PSB option menu block block (mask) does not have a parameter named ‘NonlinearTolerance’ nonlineartolerance MATLAB Answers — New Questions
Convert an 8 bit image to 12 bit
I am trying to convert an image from 8bit to 12 bit. I understand 8 bit can go from 0-256 while 12 can go from 0-4095 i believe. Basically i am using the bit value for analysis purpose so using a 12 bit image makes more sense for me. However I don’t have a lot of experience with image processing. Can i simply multiply the 8 bit values by a fraction of 256 or something similar? If anyone has any experience doing this can provide some feedback. I have read about going from 12 bit to 8 bit but it is hard to find information on going the other way.I am trying to convert an image from 8bit to 12 bit. I understand 8 bit can go from 0-256 while 12 can go from 0-4095 i believe. Basically i am using the bit value for analysis purpose so using a 12 bit image makes more sense for me. However I don’t have a lot of experience with image processing. Can i simply multiply the 8 bit values by a fraction of 256 or something similar? If anyone has any experience doing this can provide some feedback. I have read about going from 12 bit to 8 bit but it is hard to find information on going the other way. I am trying to convert an image from 8bit to 12 bit. I understand 8 bit can go from 0-256 while 12 can go from 0-4095 i believe. Basically i am using the bit value for analysis purpose so using a 12 bit image makes more sense for me. However I don’t have a lot of experience with image processing. Can i simply multiply the 8 bit values by a fraction of 256 or something similar? If anyone has any experience doing this can provide some feedback. I have read about going from 12 bit to 8 bit but it is hard to find information on going the other way. image analysis, image processing, digital image processing MATLAB Answers — New Questions
Microsoft Visual Studio 2022 set up as default C and C++ compiler in Matlab 2021a
That´s my need. It´s installed but Matlab doesn´t know that it is.
if I put: mex -setup, Microsoft visual studio doesn´t appear.
Thank you very much for helping!
What must I do in order to set Visual Studio as the Matlab C and C++ Compiler?
My default Compiler now is mingw64-g++ but I want to generate an audio plugin and it can´t be compiled, this is the message:
"Error using generateAudioPlugin
Toolchain ‘MinGW64 Compiler (C++)’ is not supported for generating audio plug-ins. Use one
of the following:
Microsoft Visual C++ 2017
Microsoft Visual C++ 2015."
Visual C++ is already installed in my desktop but how can I integrate it to MATLAB in order to be the compiler in use with it?That´s my need. It´s installed but Matlab doesn´t know that it is.
if I put: mex -setup, Microsoft visual studio doesn´t appear.
Thank you very much for helping!
What must I do in order to set Visual Studio as the Matlab C and C++ Compiler?
My default Compiler now is mingw64-g++ but I want to generate an audio plugin and it can´t be compiled, this is the message:
"Error using generateAudioPlugin
Toolchain ‘MinGW64 Compiler (C++)’ is not supported for generating audio plug-ins. Use one
of the following:
Microsoft Visual C++ 2017
Microsoft Visual C++ 2015."
Visual C++ is already installed in my desktop but how can I integrate it to MATLAB in order to be the compiler in use with it? That´s my need. It´s installed but Matlab doesn´t know that it is.
if I put: mex -setup, Microsoft visual studio doesn´t appear.
Thank you very much for helping!
What must I do in order to set Visual Studio as the Matlab C and C++ Compiler?
My default Compiler now is mingw64-g++ but I want to generate an audio plugin and it can´t be compiled, this is the message:
"Error using generateAudioPlugin
Toolchain ‘MinGW64 Compiler (C++)’ is not supported for generating audio plug-ins. Use one
of the following:
Microsoft Visual C++ 2017
Microsoft Visual C++ 2015."
Visual C++ is already installed in my desktop but how can I integrate it to MATLAB in order to be the compiler in use with it? c++ compiler set up, c++ compiler configuration MATLAB Answers — New Questions