Tag Archives: matlab
Flight Log Analyzer Error in extracting GPS and Attitude Data
Hello, I am trying to import a ulog file from a PX4 SITL flight of a UAV performed in Qgrouncontrol. The ulog file works fine and the GPS data and everything else is available when I use the PX4 online flight reviewer (https://review.px4.io/plot_app?log=b0a85256-2690-49bb-8b93-a76311c32c86), however, when I try importing the downloaded ulog file (top right on page you can download it as well), the flight log analyzer app does not display any 2D map. It lists the flight modes and their timestamps, but when I hover over the map view, I get a "Error in extracting GPS and Attitude Data" message.
When importing the ulog from into the workspace using ulogreader there is a long list of topics, and the GPS position seems to be included, but when opening the signal browser after importing the ulog file into the flight log analyzer, many of the topics seem to not have been imported?
Importing the ulog file from the tutorial works, so I am assuming that there is something wrong with my ulog file format/the way the flight analyzer is trying to read the message fields, but I am unsure what exactly the problem is. If anyone has any ideas please let me know
This is the version of Matlab I am running:
MATLAB Version: 24.1.0.2603908 (R2024a) Update 3
Operating System: Microsoft Windows 11 Home Single Language Version 10.0 (Build 22631)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
—————————————————————————————————–
MATLAB Version 24.1 (R2024a)
Simulink Version 24.1 (R2024a)
Mapping Toolbox Version 24.1 (R2024a)
Signal Processing Toolbox Version 24.1 (R2024a)
UAV Toolbox Version 24.1 (R2024a)Hello, I am trying to import a ulog file from a PX4 SITL flight of a UAV performed in Qgrouncontrol. The ulog file works fine and the GPS data and everything else is available when I use the PX4 online flight reviewer (https://review.px4.io/plot_app?log=b0a85256-2690-49bb-8b93-a76311c32c86), however, when I try importing the downloaded ulog file (top right on page you can download it as well), the flight log analyzer app does not display any 2D map. It lists the flight modes and their timestamps, but when I hover over the map view, I get a "Error in extracting GPS and Attitude Data" message.
When importing the ulog from into the workspace using ulogreader there is a long list of topics, and the GPS position seems to be included, but when opening the signal browser after importing the ulog file into the flight log analyzer, many of the topics seem to not have been imported?
Importing the ulog file from the tutorial works, so I am assuming that there is something wrong with my ulog file format/the way the flight analyzer is trying to read the message fields, but I am unsure what exactly the problem is. If anyone has any ideas please let me know
This is the version of Matlab I am running:
MATLAB Version: 24.1.0.2603908 (R2024a) Update 3
Operating System: Microsoft Windows 11 Home Single Language Version 10.0 (Build 22631)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
—————————————————————————————————–
MATLAB Version 24.1 (R2024a)
Simulink Version 24.1 (R2024a)
Mapping Toolbox Version 24.1 (R2024a)
Signal Processing Toolbox Version 24.1 (R2024a)
UAV Toolbox Version 24.1 (R2024a) Hello, I am trying to import a ulog file from a PX4 SITL flight of a UAV performed in Qgrouncontrol. The ulog file works fine and the GPS data and everything else is available when I use the PX4 online flight reviewer (https://review.px4.io/plot_app?log=b0a85256-2690-49bb-8b93-a76311c32c86), however, when I try importing the downloaded ulog file (top right on page you can download it as well), the flight log analyzer app does not display any 2D map. It lists the flight modes and their timestamps, but when I hover over the map view, I get a "Error in extracting GPS and Attitude Data" message.
When importing the ulog from into the workspace using ulogreader there is a long list of topics, and the GPS position seems to be included, but when opening the signal browser after importing the ulog file into the flight log analyzer, many of the topics seem to not have been imported?
Importing the ulog file from the tutorial works, so I am assuming that there is something wrong with my ulog file format/the way the flight analyzer is trying to read the message fields, but I am unsure what exactly the problem is. If anyone has any ideas please let me know
This is the version of Matlab I am running:
MATLAB Version: 24.1.0.2603908 (R2024a) Update 3
Operating System: Microsoft Windows 11 Home Single Language Version 10.0 (Build 22631)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
—————————————————————————————————–
MATLAB Version 24.1 (R2024a)
Simulink Version 24.1 (R2024a)
Mapping Toolbox Version 24.1 (R2024a)
Signal Processing Toolbox Version 24.1 (R2024a)
UAV Toolbox Version 24.1 (R2024a) ulog, px4, qgrouncontrol, flightloganalyzer MATLAB Answers — New Questions
Matlab function “pyenv”
I need to convert one function from Matlab to Python. My Matlab version is R2022.b. Compatible Python version is 3.10. Both Matlab and Python are now installed on my PC. When I run the function "pyenv" in Matlab, I receive empty fields and message "Python commands require a supported version of CPython."
Regarding Matlab, I have: Matlab, Financial Toolbox, Optimization Toolbox, and Statistics and Machine Learning Toolbox.
Do I need to get some other toolboxes for Matlab to be able to see/work with Python?
Thank you.
StefanI need to convert one function from Matlab to Python. My Matlab version is R2022.b. Compatible Python version is 3.10. Both Matlab and Python are now installed on my PC. When I run the function "pyenv" in Matlab, I receive empty fields and message "Python commands require a supported version of CPython."
Regarding Matlab, I have: Matlab, Financial Toolbox, Optimization Toolbox, and Statistics and Machine Learning Toolbox.
Do I need to get some other toolboxes for Matlab to be able to see/work with Python?
Thank you.
Stefan I need to convert one function from Matlab to Python. My Matlab version is R2022.b. Compatible Python version is 3.10. Both Matlab and Python are now installed on my PC. When I run the function "pyenv" in Matlab, I receive empty fields and message "Python commands require a supported version of CPython."
Regarding Matlab, I have: Matlab, Financial Toolbox, Optimization Toolbox, and Statistics and Machine Learning Toolbox.
Do I need to get some other toolboxes for Matlab to be able to see/work with Python?
Thank you.
Stefan matlab to python, python MATLAB Answers — New Questions
syntax error in if else if block
how to write else if condition with multiple inputs
else if condition is throwing an error.how to write else if condition with multiple inputs
else if condition is throwing an error. how to write else if condition with multiple inputs
else if condition is throwing an error. if statement, error MATLAB Answers — New Questions
In this work, I am trying to connect two systems by injecting a delayed wave of the first system into the second system. In this system, there are several problems, including:
function [sol1] = two_system
clc
close all
clear all
global z; %%problems
%%1- The indices for the two systems cannot be equal.
%%2- The global function is only valid for one value of (MD) …
%%(the last value), while I need all values from the first system.
z= 0.05;
tau = 0.1;
tspan = linspace(0, 5, 300);
opt = odeset(‘RelTol’,1e-3);
sol1 = dde23(@system1,tau ,[0],tspan, opt);
[x1, y1] = ode23(@system2, tspan, [0], opt);
figure(1)
plot(sol1.x, sol1.y(1,:),’–r’,’LineWidth’,1.5)
hold on
plot(x1, y1(:,1),’b’,’LineWidth’,1.5)
L2=length(x1)
L1=length(sol1.x)
end
function dydt = system1(t,y,D)
global z MD;
M1 = y(1);
MD = D(1);
s1 = MD %for checking
F_M1= 2;
theta1=0*pi/180;
A1 = 0.01;
%%%%%%% equation_system1 %%%%%%%
dMdt=(A1*(2*pi*(F_M1))*cos(2*pi*(F_M1)*(t)+theta1));
dydt = [dMdt];
end
function dydt = system2(t,y)
global z MD;
s2=MD %% for checking
M2 = y(1);
F_M2= 2;
theta2=0*pi/180;
A2 = 0.01;
%%%%%%% equation_system2 %%%%%%%
dMdt=(A2*(2*pi*(F_M2))*cos(2*pi*(F_M2)*(t)+theta2))+MD*z;
dydt = [dMdt];
endfunction [sol1] = two_system
clc
close all
clear all
global z; %%problems
%%1- The indices for the two systems cannot be equal.
%%2- The global function is only valid for one value of (MD) …
%%(the last value), while I need all values from the first system.
z= 0.05;
tau = 0.1;
tspan = linspace(0, 5, 300);
opt = odeset(‘RelTol’,1e-3);
sol1 = dde23(@system1,tau ,[0],tspan, opt);
[x1, y1] = ode23(@system2, tspan, [0], opt);
figure(1)
plot(sol1.x, sol1.y(1,:),’–r’,’LineWidth’,1.5)
hold on
plot(x1, y1(:,1),’b’,’LineWidth’,1.5)
L2=length(x1)
L1=length(sol1.x)
end
function dydt = system1(t,y,D)
global z MD;
M1 = y(1);
MD = D(1);
s1 = MD %for checking
F_M1= 2;
theta1=0*pi/180;
A1 = 0.01;
%%%%%%% equation_system1 %%%%%%%
dMdt=(A1*(2*pi*(F_M1))*cos(2*pi*(F_M1)*(t)+theta1));
dydt = [dMdt];
end
function dydt = system2(t,y)
global z MD;
s2=MD %% for checking
M2 = y(1);
F_M2= 2;
theta2=0*pi/180;
A2 = 0.01;
%%%%%%% equation_system2 %%%%%%%
dMdt=(A2*(2*pi*(F_M2))*cos(2*pi*(F_M2)*(t)+theta2))+MD*z;
dydt = [dMdt];
end function [sol1] = two_system
clc
close all
clear all
global z; %%problems
%%1- The indices for the two systems cannot be equal.
%%2- The global function is only valid for one value of (MD) …
%%(the last value), while I need all values from the first system.
z= 0.05;
tau = 0.1;
tspan = linspace(0, 5, 300);
opt = odeset(‘RelTol’,1e-3);
sol1 = dde23(@system1,tau ,[0],tspan, opt);
[x1, y1] = ode23(@system2, tspan, [0], opt);
figure(1)
plot(sol1.x, sol1.y(1,:),’–r’,’LineWidth’,1.5)
hold on
plot(x1, y1(:,1),’b’,’LineWidth’,1.5)
L2=length(x1)
L1=length(sol1.x)
end
function dydt = system1(t,y,D)
global z MD;
M1 = y(1);
MD = D(1);
s1 = MD %for checking
F_M1= 2;
theta1=0*pi/180;
A1 = 0.01;
%%%%%%% equation_system1 %%%%%%%
dMdt=(A1*(2*pi*(F_M1))*cos(2*pi*(F_M1)*(t)+theta1));
dydt = [dMdt];
end
function dydt = system2(t,y)
global z MD;
s2=MD %% for checking
M2 = y(1);
F_M2= 2;
theta2=0*pi/180;
A2 = 0.01;
%%%%%%% equation_system2 %%%%%%%
dMdt=(A2*(2*pi*(F_M2))*cos(2*pi*(F_M2)*(t)+theta2))+MD*z;
dydt = [dMdt];
end sam chak MATLAB Answers — New Questions
Neural Network form Parameters to Simple Image Generation
Hello everyone,
I am currently working on a project where I need to generate black and white images of squares based on three parameters: the center x coordinate, the center y coordinate, and the edge length of the square. This would be extremely easy by itself but I must do it through e neural network or other type of ML approach. Below is a small example of a 10-samples dataset.
Could anyone provide guidance on how to design and train a neural network for this purpose? Specifically, I am looking for insights into:
Choosing the appropriate neural network architecture (e.g., convolutional neural network, feedforward neural network).
Preprocessing steps required for the input data.
Methods for structuring the output layer to generate the B/W image of the square.
Techniques for training the neural network using a dataset of square images with known parameters.
Any advice, sample code, or relevant resources would be greatly appreciated.
Thank you in advance for your assistance.
Best regards,
DanieleHello everyone,
I am currently working on a project where I need to generate black and white images of squares based on three parameters: the center x coordinate, the center y coordinate, and the edge length of the square. This would be extremely easy by itself but I must do it through e neural network or other type of ML approach. Below is a small example of a 10-samples dataset.
Could anyone provide guidance on how to design and train a neural network for this purpose? Specifically, I am looking for insights into:
Choosing the appropriate neural network architecture (e.g., convolutional neural network, feedforward neural network).
Preprocessing steps required for the input data.
Methods for structuring the output layer to generate the B/W image of the square.
Techniques for training the neural network using a dataset of square images with known parameters.
Any advice, sample code, or relevant resources would be greatly appreciated.
Thank you in advance for your assistance.
Best regards,
Daniele Hello everyone,
I am currently working on a project where I need to generate black and white images of squares based on three parameters: the center x coordinate, the center y coordinate, and the edge length of the square. This would be extremely easy by itself but I must do it through e neural network or other type of ML approach. Below is a small example of a 10-samples dataset.
Could anyone provide guidance on how to design and train a neural network for this purpose? Specifically, I am looking for insights into:
Choosing the appropriate neural network architecture (e.g., convolutional neural network, feedforward neural network).
Preprocessing steps required for the input data.
Methods for structuring the output layer to generate the B/W image of the square.
Techniques for training the neural network using a dataset of square images with known parameters.
Any advice, sample code, or relevant resources would be greatly appreciated.
Thank you in advance for your assistance.
Best regards,
Daniele neural network, image generation MATLAB Answers — New Questions
Merge two plots with the same y axis
Hello there,
I have two sets of parameter, x1 and x2 and they both vary with depth. Since the scale span of x1 is different to that of x2, what I want to do is to put the axis of x2 above, as the secondary plot (see fig below). Anyone can help me to fix this?
x1 = 0:0.1:5;
y1 = 0:1:50;
y2 = 0:1:90;
x2 = y2.^0.9;
figure;
subplot(1,2,1)
plot(x1,y1);
ylabel(‘Depth (m)’);
xlabel(‘Length’);
subplot(1,2,2);
plot(x2,y2,’r’);
ylabel(‘Depth (m)’);
xlabel(‘Power’);
Please find attached the data, or please access the code above to generate the data.
ThanksHello there,
I have two sets of parameter, x1 and x2 and they both vary with depth. Since the scale span of x1 is different to that of x2, what I want to do is to put the axis of x2 above, as the secondary plot (see fig below). Anyone can help me to fix this?
x1 = 0:0.1:5;
y1 = 0:1:50;
y2 = 0:1:90;
x2 = y2.^0.9;
figure;
subplot(1,2,1)
plot(x1,y1);
ylabel(‘Depth (m)’);
xlabel(‘Length’);
subplot(1,2,2);
plot(x2,y2,’r’);
ylabel(‘Depth (m)’);
xlabel(‘Power’);
Please find attached the data, or please access the code above to generate the data.
Thanks Hello there,
I have two sets of parameter, x1 and x2 and they both vary with depth. Since the scale span of x1 is different to that of x2, what I want to do is to put the axis of x2 above, as the secondary plot (see fig below). Anyone can help me to fix this?
x1 = 0:0.1:5;
y1 = 0:1:50;
y2 = 0:1:90;
x2 = y2.^0.9;
figure;
subplot(1,2,1)
plot(x1,y1);
ylabel(‘Depth (m)’);
xlabel(‘Length’);
subplot(1,2,2);
plot(x2,y2,’r’);
ylabel(‘Depth (m)’);
xlabel(‘Power’);
Please find attached the data, or please access the code above to generate the data.
Thanks overlay plot, two axis MATLAB Answers — New Questions
Why do I get the warning: “Error updating Axes. DataSpace or ColorSpace conversion method failed.” ?
X = logspace(-4,1,2e3);
Y = abs(randn(length(X),1))*1e2;
figure
yyaxis left
loglog(X,Y);
ylim([1e-3,1e3])
yyaxis right
loglog(X,Y*1e-5);
ylim([1e-3*1e-5,1e3*1e-5])
When I’m using yyaxis, I want the coordinates on both sides to show different units of the same set of data, but I run into the above warning. Minimum working example is given.X = logspace(-4,1,2e3);
Y = abs(randn(length(X),1))*1e2;
figure
yyaxis left
loglog(X,Y);
ylim([1e-3,1e3])
yyaxis right
loglog(X,Y*1e-5);
ylim([1e-3*1e-5,1e3*1e-5])
When I’m using yyaxis, I want the coordinates on both sides to show different units of the same set of data, but I run into the above warning. Minimum working example is given. X = logspace(-4,1,2e3);
Y = abs(randn(length(X),1))*1e2;
figure
yyaxis left
loglog(X,Y);
ylim([1e-3,1e3])
yyaxis right
loglog(X,Y*1e-5);
ylim([1e-3*1e-5,1e3*1e-5])
When I’m using yyaxis, I want the coordinates on both sides to show different units of the same set of data, but I run into the above warning. Minimum working example is given. updating axes,, dataspace or colorspace conversion MATLAB Answers — New Questions
Weird Imhist beahviour seen
Hi, ive been tearing my hair out all morning. I want to plot the histogram of an image. I normally use im hist. My images are 3 12 bit images that are summed, hence the max value can be 3*4095=12285. It appears my histogram is defaulting to 16 bit values.
This is my code:
IM = imread(file);
IM1=double(IM);
[maxval,idx]=max(IM1(:)) % determine number of bins (of width = unity)
maxval= double(maxval);
[counts,x] = imhist(IM,maxval);
figure
stem(x,counts,’b’, ‘.’);
counts(maxval) %check the max intensity
First of all, counts(maxval) returns zero, and here is the histogram stem plot – defaulting to 65535 levels. I want to have 1-12285 levels.
<</matlabcentral/answers/uploaded_files/21461/img21.png>>Hi, ive been tearing my hair out all morning. I want to plot the histogram of an image. I normally use im hist. My images are 3 12 bit images that are summed, hence the max value can be 3*4095=12285. It appears my histogram is defaulting to 16 bit values.
This is my code:
IM = imread(file);
IM1=double(IM);
[maxval,idx]=max(IM1(:)) % determine number of bins (of width = unity)
maxval= double(maxval);
[counts,x] = imhist(IM,maxval);
figure
stem(x,counts,’b’, ‘.’);
counts(maxval) %check the max intensity
First of all, counts(maxval) returns zero, and here is the histogram stem plot – defaulting to 65535 levels. I want to have 1-12285 levels.
<</matlabcentral/answers/uploaded_files/21461/img21.png>> Hi, ive been tearing my hair out all morning. I want to plot the histogram of an image. I normally use im hist. My images are 3 12 bit images that are summed, hence the max value can be 3*4095=12285. It appears my histogram is defaulting to 16 bit values.
This is my code:
IM = imread(file);
IM1=double(IM);
[maxval,idx]=max(IM1(:)) % determine number of bins (of width = unity)
maxval= double(maxval);
[counts,x] = imhist(IM,maxval);
figure
stem(x,counts,’b’, ‘.’);
counts(maxval) %check the max intensity
First of all, counts(maxval) returns zero, and here is the histogram stem plot – defaulting to 65535 levels. I want to have 1-12285 levels.
<</matlabcentral/answers/uploaded_files/21461/img21.png>> imhist MATLAB Answers — New Questions
Calibrate camera to IMU
Hi all,
I would like to calculate the Extrinsic transformation matrix (rotation and translation) between camera and IMU that I have on the same board. The matrix should be 4×4 dimensions (please see image attached).
I saw that is common to use Kalibr software to this but I would like to implement this in Matlab.
Can anyone help me with this issue? Is there a code that does something like this?
Thanks,
ItaiHi all,
I would like to calculate the Extrinsic transformation matrix (rotation and translation) between camera and IMU that I have on the same board. The matrix should be 4×4 dimensions (please see image attached).
I saw that is common to use Kalibr software to this but I would like to implement this in Matlab.
Can anyone help me with this issue? Is there a code that does something like this?
Thanks,
Itai Hi all,
I would like to calculate the Extrinsic transformation matrix (rotation and translation) between camera and IMU that I have on the same board. The matrix should be 4×4 dimensions (please see image attached).
I saw that is common to use Kalibr software to this but I would like to implement this in Matlab.
Can anyone help me with this issue? Is there a code that does something like this?
Thanks,
Itai camera to imu MATLAB Answers — New Questions
help using bsxfun to multiplay different size matrixes
I want to make the following:
create a matrix that has one more diamention the the matrix norm_mode (actuatty is to make a norm_mode a time function)
to accelrate it on matlab I tryied the use of bsxfun, but I get the error : "Non-singleton dimensions of the two input arrays must match each other."
Please help me fix it, I cant tell where the problem is.
tmp = zeros(newSize, newSize, length(others.t));
for idx_t = 1:length(t)
tmp(:,:,idx_t) = norm_mode(:,:) .* fields(idx_t,3) ;
end
tmp = bsxfun(@times, norm_mode, fields(:, ii));I want to make the following:
create a matrix that has one more diamention the the matrix norm_mode (actuatty is to make a norm_mode a time function)
to accelrate it on matlab I tryied the use of bsxfun, but I get the error : "Non-singleton dimensions of the two input arrays must match each other."
Please help me fix it, I cant tell where the problem is.
tmp = zeros(newSize, newSize, length(others.t));
for idx_t = 1:length(t)
tmp(:,:,idx_t) = norm_mode(:,:) .* fields(idx_t,3) ;
end
tmp = bsxfun(@times, norm_mode, fields(:, ii)); I want to make the following:
create a matrix that has one more diamention the the matrix norm_mode (actuatty is to make a norm_mode a time function)
to accelrate it on matlab I tryied the use of bsxfun, but I get the error : "Non-singleton dimensions of the two input arrays must match each other."
Please help me fix it, I cant tell where the problem is.
tmp = zeros(newSize, newSize, length(others.t));
for idx_t = 1:length(t)
tmp(:,:,idx_t) = norm_mode(:,:) .* fields(idx_t,3) ;
end
tmp = bsxfun(@times, norm_mode, fields(:, ii)); bsxfun, matlab MATLAB Answers — New Questions
Is my DDPG agent learning?
Hello everyone,
Can I conclude that my agent is learning? (maximum reward per episode is 20).
In the first image, the reward was low (-5) for the first episode, and it can be observed that the average reward starts to increase from episode 80. However, it fluctuates between 5 and 20 after episode 100. Reading other questions, it was mentioned that Q0 could help determine if the agent is learning, and as it approaches the maximum reward, I think it could be determined that it is learning. However, what makes me doubt the learning are the fluctuations in rewards after episode 100.
Another thing that makes me doubt if the agent is learning is that, while conducting another training session (image 2), the fluctuations in the average rewards are more noticeable. Even though Q0 still tends towards the maximum reward (20), in both training sessions, they continue to receive negative rewards (more than expected).
So it’s difficult for me to determine if the agent is learning. If that’s not the case, what should I modify? The reward? The agent’s hyperparameters?
I would greatly appreciate your guidance.Hello everyone,
Can I conclude that my agent is learning? (maximum reward per episode is 20).
In the first image, the reward was low (-5) for the first episode, and it can be observed that the average reward starts to increase from episode 80. However, it fluctuates between 5 and 20 after episode 100. Reading other questions, it was mentioned that Q0 could help determine if the agent is learning, and as it approaches the maximum reward, I think it could be determined that it is learning. However, what makes me doubt the learning are the fluctuations in rewards after episode 100.
Another thing that makes me doubt if the agent is learning is that, while conducting another training session (image 2), the fluctuations in the average rewards are more noticeable. Even though Q0 still tends towards the maximum reward (20), in both training sessions, they continue to receive negative rewards (more than expected).
So it’s difficult for me to determine if the agent is learning. If that’s not the case, what should I modify? The reward? The agent’s hyperparameters?
I would greatly appreciate your guidance. Hello everyone,
Can I conclude that my agent is learning? (maximum reward per episode is 20).
In the first image, the reward was low (-5) for the first episode, and it can be observed that the average reward starts to increase from episode 80. However, it fluctuates between 5 and 20 after episode 100. Reading other questions, it was mentioned that Q0 could help determine if the agent is learning, and as it approaches the maximum reward, I think it could be determined that it is learning. However, what makes me doubt the learning are the fluctuations in rewards after episode 100.
Another thing that makes me doubt if the agent is learning is that, while conducting another training session (image 2), the fluctuations in the average rewards are more noticeable. Even though Q0 still tends towards the maximum reward (20), in both training sessions, they continue to receive negative rewards (more than expected).
So it’s difficult for me to determine if the agent is learning. If that’s not the case, what should I modify? The reward? The agent’s hyperparameters?
I would greatly appreciate your guidance. reinforcement learning, ddpg agent MATLAB Answers — New Questions
Problem with Imhist method
I have an image Zoom:
Zoom =
326 313 269 237 255 329
332 271 304 256 332 302
330 320 265 215 274 316
233 219 218 224 221 224
260 224 203 226 193 210
272 231 219 227 205 227
when I perform
figure
imhist(Zoom)
the histogram is defaulting in the x-axis to x10^4
<</matlabcentral/answers/uploaded_files/19890/img11.png>>
So the histogram is just a spike.
why does it not autorange the x-axis, and how too?
thanks
JasonI have an image Zoom:
Zoom =
326 313 269 237 255 329
332 271 304 256 332 302
330 320 265 215 274 316
233 219 218 224 221 224
260 224 203 226 193 210
272 231 219 227 205 227
when I perform
figure
imhist(Zoom)
the histogram is defaulting in the x-axis to x10^4
<</matlabcentral/answers/uploaded_files/19890/img11.png>>
So the histogram is just a spike.
why does it not autorange the x-axis, and how too?
thanks
Jason I have an image Zoom:
Zoom =
326 313 269 237 255 329
332 271 304 256 332 302
330 320 265 215 274 316
233 219 218 224 221 224
260 224 203 226 193 210
272 231 219 227 205 227
when I perform
figure
imhist(Zoom)
the histogram is defaulting in the x-axis to x10^4
<</matlabcentral/answers/uploaded_files/19890/img11.png>>
So the histogram is just a spike.
why does it not autorange the x-axis, and how too?
thanks
Jason imhist MATLAB Answers — New Questions
How can I add ‘MISRA C:2023’ to Code Generation Objectives?
How can I add ‘MISRA C:2023’ to Code Generation Objectives?How can I add ‘MISRA C:2023’ to Code Generation Objectives? How can I add ‘MISRA C:2023’ to Code Generation Objectives? misra c:2023, code generation MATLAB Answers — New Questions
Download the entire product offline
How can I download Matlab R2015a so that I don’t need internet connection while installing on any other machine?How can I download Matlab R2015a so that I don’t need internet connection while installing on any other machine? How can I download Matlab R2015a so that I don’t need internet connection while installing on any other machine? offline, download MATLAB Answers — New Questions
Improve convergence of GD with momentum
Hello,
I have made a simple implementation of the GD algorithm with momentum and it seems to me that convergence is very slow, it takes about 15k iterations to reach predefined tolerance.
I feel like there should be an improvement to this code, but I don’t see where.
Please, suggest me a better implementation:
clear all
clc
% Initial guess
x0 = [1.3, 0.7, 0.8, 1.9, 1.2]’;
% Parameters
alpha = 0.001;
beta = 0.4;
max_iter = 10000;
tol = 1e-8;
x = x0; % find the values of x that minimize␣
i = 0;
step = zeros(size(x));
mse = rosenbrock(x);
fprintf(‘Initial MSE = %14.10f x = %sn’, mse, mat2str(x’)); % print initial values
while mse > tol
grad = rosenbrock_gradient(x);
gnorm = norm(grad); % gradient norm
step = -(1-beta)*alpha*grad + beta*step;
x = x + step;
mse = rosenbrock(x); % update the mean squared error
i = i + 1;
end
fprintf(‘iterations = %6dn’, i);
fprintf(‘Final MSE = %14.10f x = %sn’, mse, mat2str(x’));
fprintf(‘gradient = %sn’, mat2str(grad’));
fprintf(‘gradient norm = %fn’, gnorm);
% Define the Rosenbrock function
function [mse] = rosenbrock(x)
mse = sum(100.0 * (x(2:end) – x(1:end-1).^2.0).^2.0 + (1 – x(1:end-1)).^2.0);
end
% Define the gradient of the Rosenbrock function
function [grad] = rosenbrock_gradient(x)
n = length(x);
grad = zeros(n, 1);
grad(1) = -400 * x(1) * (x(2) – x(1)^2) – 2 * (1 – x(1));
grad(2:n-1) = 200 * (x(2:n-1) – x(1:n-2).^2) – 400 * x(2:n-1) .* (x(3:n) – x(2:n-1).^2) – 2 * (1 – x(2:n-1));
grad(n) = 200 * (x(n) – x(n-1)^2);
endHello,
I have made a simple implementation of the GD algorithm with momentum and it seems to me that convergence is very slow, it takes about 15k iterations to reach predefined tolerance.
I feel like there should be an improvement to this code, but I don’t see where.
Please, suggest me a better implementation:
clear all
clc
% Initial guess
x0 = [1.3, 0.7, 0.8, 1.9, 1.2]’;
% Parameters
alpha = 0.001;
beta = 0.4;
max_iter = 10000;
tol = 1e-8;
x = x0; % find the values of x that minimize␣
i = 0;
step = zeros(size(x));
mse = rosenbrock(x);
fprintf(‘Initial MSE = %14.10f x = %sn’, mse, mat2str(x’)); % print initial values
while mse > tol
grad = rosenbrock_gradient(x);
gnorm = norm(grad); % gradient norm
step = -(1-beta)*alpha*grad + beta*step;
x = x + step;
mse = rosenbrock(x); % update the mean squared error
i = i + 1;
end
fprintf(‘iterations = %6dn’, i);
fprintf(‘Final MSE = %14.10f x = %sn’, mse, mat2str(x’));
fprintf(‘gradient = %sn’, mat2str(grad’));
fprintf(‘gradient norm = %fn’, gnorm);
% Define the Rosenbrock function
function [mse] = rosenbrock(x)
mse = sum(100.0 * (x(2:end) – x(1:end-1).^2.0).^2.0 + (1 – x(1:end-1)).^2.0);
end
% Define the gradient of the Rosenbrock function
function [grad] = rosenbrock_gradient(x)
n = length(x);
grad = zeros(n, 1);
grad(1) = -400 * x(1) * (x(2) – x(1)^2) – 2 * (1 – x(1));
grad(2:n-1) = 200 * (x(2:n-1) – x(1:n-2).^2) – 400 * x(2:n-1) .* (x(3:n) – x(2:n-1).^2) – 2 * (1 – x(2:n-1));
grad(n) = 200 * (x(n) – x(n-1)^2);
end Hello,
I have made a simple implementation of the GD algorithm with momentum and it seems to me that convergence is very slow, it takes about 15k iterations to reach predefined tolerance.
I feel like there should be an improvement to this code, but I don’t see where.
Please, suggest me a better implementation:
clear all
clc
% Initial guess
x0 = [1.3, 0.7, 0.8, 1.9, 1.2]’;
% Parameters
alpha = 0.001;
beta = 0.4;
max_iter = 10000;
tol = 1e-8;
x = x0; % find the values of x that minimize␣
i = 0;
step = zeros(size(x));
mse = rosenbrock(x);
fprintf(‘Initial MSE = %14.10f x = %sn’, mse, mat2str(x’)); % print initial values
while mse > tol
grad = rosenbrock_gradient(x);
gnorm = norm(grad); % gradient norm
step = -(1-beta)*alpha*grad + beta*step;
x = x + step;
mse = rosenbrock(x); % update the mean squared error
i = i + 1;
end
fprintf(‘iterations = %6dn’, i);
fprintf(‘Final MSE = %14.10f x = %sn’, mse, mat2str(x’));
fprintf(‘gradient = %sn’, mat2str(grad’));
fprintf(‘gradient norm = %fn’, gnorm);
% Define the Rosenbrock function
function [mse] = rosenbrock(x)
mse = sum(100.0 * (x(2:end) – x(1:end-1).^2.0).^2.0 + (1 – x(1:end-1)).^2.0);
end
% Define the gradient of the Rosenbrock function
function [grad] = rosenbrock_gradient(x)
n = length(x);
grad = zeros(n, 1);
grad(1) = -400 * x(1) * (x(2) – x(1)^2) – 2 * (1 – x(1));
grad(2:n-1) = 200 * (x(2:n-1) – x(1:n-2).^2) – 400 * x(2:n-1) .* (x(3:n) – x(2:n-1).^2) – 2 * (1 – x(2:n-1));
grad(n) = 200 * (x(n) – x(n-1)^2);
end gd with momentum MATLAB Answers — New Questions
FMU export Algebraic loop error
I am getting the below error while exporting the simulink/simscape model to FMU.
I converted all subsytems to atomic to remove similar error/ algebraic
fmu_exp/Solver Configuration/EVAL_KEY/INPUT_1_1_1 (algebraic variable) This algebraic loop may be resolved when the subsystem option ‘Minimize algebraic loop occurrences’ is selected on some or all of the atomic and enabled subsystems in this algebraic loop
Component:Simulink | Category:Model
Algebraic loops are not supported in generated code. Use the ‘ashow’ command in the Simulink Debugger to see the algebraic loopsI am getting the below error while exporting the simulink/simscape model to FMU.
I converted all subsytems to atomic to remove similar error/ algebraic
fmu_exp/Solver Configuration/EVAL_KEY/INPUT_1_1_1 (algebraic variable) This algebraic loop may be resolved when the subsystem option ‘Minimize algebraic loop occurrences’ is selected on some or all of the atomic and enabled subsystems in this algebraic loop
Component:Simulink | Category:Model
Algebraic loops are not supported in generated code. Use the ‘ashow’ command in the Simulink Debugger to see the algebraic loops I am getting the below error while exporting the simulink/simscape model to FMU.
I converted all subsytems to atomic to remove similar error/ algebraic
fmu_exp/Solver Configuration/EVAL_KEY/INPUT_1_1_1 (algebraic variable) This algebraic loop may be resolved when the subsystem option ‘Minimize algebraic loop occurrences’ is selected on some or all of the atomic and enabled subsystems in this algebraic loop
Component:Simulink | Category:Model
Algebraic loops are not supported in generated code. Use the ‘ashow’ command in the Simulink Debugger to see the algebraic loops simulink MATLAB Answers — New Questions
Convolution of two matrixes of PDF values
Hello,
I’m trying to write a function that looks like something like this: convolved_matrix = convolve_matrixes(matrix1, matrix2), where the matrixes are N x 2 large (N rows and 2 columns). These matrixes is containing PDF values where on the first column contains the indexes and the second column contains the probabilities. So my question is how can i obtain a matrix that contains the correct convolution with correct index values and probability values between the inputed matrixes?Hello,
I’m trying to write a function that looks like something like this: convolved_matrix = convolve_matrixes(matrix1, matrix2), where the matrixes are N x 2 large (N rows and 2 columns). These matrixes is containing PDF values where on the first column contains the indexes and the second column contains the probabilities. So my question is how can i obtain a matrix that contains the correct convolution with correct index values and probability values between the inputed matrixes? Hello,
I’m trying to write a function that looks like something like this: convolved_matrix = convolve_matrixes(matrix1, matrix2), where the matrixes are N x 2 large (N rows and 2 columns). These matrixes is containing PDF values where on the first column contains the indexes and the second column contains the probabilities. So my question is how can i obtain a matrix that contains the correct convolution with correct index values and probability values between the inputed matrixes? matrix MATLAB Answers — New Questions
Could MatLAB model be exported to FMU without Simulink?
Is it possible to export an MatLab-Model to FMU for use in an Co-Simulation without SimuLink?
Or is the FMU-Interface a part of SimuLink?
Motivation: We have a set of current equations we want to solve in a co-simulation and want to use FMI/FMU for connecting MatLab with CCM+. We do not want to create an SimuLink-Model but want to use these equation. Is this way to connect the Software-packages possible?Is it possible to export an MatLab-Model to FMU for use in an Co-Simulation without SimuLink?
Or is the FMU-Interface a part of SimuLink?
Motivation: We have a set of current equations we want to solve in a co-simulation and want to use FMI/FMU for connecting MatLab with CCM+. We do not want to create an SimuLink-Model but want to use these equation. Is this way to connect the Software-packages possible? Is it possible to export an MatLab-Model to FMU for use in an Co-Simulation without SimuLink?
Or is the FMU-Interface a part of SimuLink?
Motivation: We have a set of current equations we want to solve in a co-simulation and want to use FMI/FMU for connecting MatLab with CCM+. We do not want to create an SimuLink-Model but want to use these equation. Is this way to connect the Software-packages possible? fmi/fmu, matlab, simulink MATLAB Answers — New Questions
how to plot from CSV files?
Hi all,
I have some data as CSV and want to plot the time (col. 1,2) in x-axis with temperature (col. 3) in y-axis (screenshot)
how to :
access the data
plot the data
thanks!!Hi all,
I have some data as CSV and want to plot the time (col. 1,2) in x-axis with temperature (col. 3) in y-axis (screenshot)
how to :
access the data
plot the data
thanks!! Hi all,
I have some data as CSV and want to plot the time (col. 1,2) in x-axis with temperature (col. 3) in y-axis (screenshot)
how to :
access the data
plot the data
thanks!! time series, csv MATLAB Answers — New Questions
setting radiobutton value by program
I have a panel with several radiobuttons so that only one of them is selected at the time, it works fine with my mouse. However, I want to create a pushbutton that when I push it will select a specific radiobutton on the panel
So for example I have radiobuttons A B and C and I clicked on C at one time then with the pushbutton I want to set A again as if I have clicked A with my mouse.. how can I do that??
Thank you in advance…I have a panel with several radiobuttons so that only one of them is selected at the time, it works fine with my mouse. However, I want to create a pushbutton that when I push it will select a specific radiobutton on the panel
So for example I have radiobuttons A B and C and I clicked on C at one time then with the pushbutton I want to set A again as if I have clicked A with my mouse.. how can I do that??
Thank you in advance… I have a panel with several radiobuttons so that only one of them is selected at the time, it works fine with my mouse. However, I want to create a pushbutton that when I push it will select a specific radiobutton on the panel
So for example I have radiobuttons A B and C and I clicked on C at one time then with the pushbutton I want to set A again as if I have clicked A with my mouse.. how can I do that??
Thank you in advance… gui guide panels MATLAB Answers — New Questions