Tag Archives: matlab
MATLAB Function always infers outputs as doubles
First, context: I’m attempting to generate HDL code from a Simulink model, which includes a MATLAB Function block. The relevant function is:
function [output, valid] = demux(input)
%#codegen
num_outputs = 24;
% Memory element: demultiplexed outputs
persistent demuxed;
if isempty(demuxed)
demuxed = zeros(num_outputs, 1, ‘like’, input);
end
% Assign from "input" to a single element of "demuxed" here… trimmed for length
% Commit actual values
output = demuxed(1:num_outputs, 1);
In my Simulink model, both input and output are sfix24_En23 types (fixed-point, signed, 24 bits total, 23 bits fractional):
I’ve tried to hint to MATLAB that output should be fixed-point as well, even including this line at the beginning of the function:
output = fi(zeros(num_outputs, 1), true, 24, 23);
This explicitly includes my fixed-point parameters, which isn’t great for maintainability, but would be acceptable for now in order to allow the model to compile.
However, in this and every other case I’ve tested, the Simulink console complains that Inferred type (‘double’) for data ‘output’ does not match back propagated type (’embedded.fi (sfix24_En23)’) from Simulink. Is there a way to make MATLAB realize that the output isn’t actually a double?First, context: I’m attempting to generate HDL code from a Simulink model, which includes a MATLAB Function block. The relevant function is:
function [output, valid] = demux(input)
%#codegen
num_outputs = 24;
% Memory element: demultiplexed outputs
persistent demuxed;
if isempty(demuxed)
demuxed = zeros(num_outputs, 1, ‘like’, input);
end
% Assign from "input" to a single element of "demuxed" here… trimmed for length
% Commit actual values
output = demuxed(1:num_outputs, 1);
In my Simulink model, both input and output are sfix24_En23 types (fixed-point, signed, 24 bits total, 23 bits fractional):
I’ve tried to hint to MATLAB that output should be fixed-point as well, even including this line at the beginning of the function:
output = fi(zeros(num_outputs, 1), true, 24, 23);
This explicitly includes my fixed-point parameters, which isn’t great for maintainability, but would be acceptable for now in order to allow the model to compile.
However, in this and every other case I’ve tested, the Simulink console complains that Inferred type (‘double’) for data ‘output’ does not match back propagated type (’embedded.fi (sfix24_En23)’) from Simulink. Is there a way to make MATLAB realize that the output isn’t actually a double? First, context: I’m attempting to generate HDL code from a Simulink model, which includes a MATLAB Function block. The relevant function is:
function [output, valid] = demux(input)
%#codegen
num_outputs = 24;
% Memory element: demultiplexed outputs
persistent demuxed;
if isempty(demuxed)
demuxed = zeros(num_outputs, 1, ‘like’, input);
end
% Assign from "input" to a single element of "demuxed" here… trimmed for length
% Commit actual values
output = demuxed(1:num_outputs, 1);
In my Simulink model, both input and output are sfix24_En23 types (fixed-point, signed, 24 bits total, 23 bits fractional):
I’ve tried to hint to MATLAB that output should be fixed-point as well, even including this line at the beginning of the function:
output = fi(zeros(num_outputs, 1), true, 24, 23);
This explicitly includes my fixed-point parameters, which isn’t great for maintainability, but would be acceptable for now in order to allow the model to compile.
However, in this and every other case I’ve tested, the Simulink console complains that Inferred type (‘double’) for data ‘output’ does not match back propagated type (’embedded.fi (sfix24_En23)’) from Simulink. Is there a way to make MATLAB realize that the output isn’t actually a double? codegen, fixed-point MATLAB Answers — New Questions
How to add a folder permanently to matlab path?
I am using addpath to add specified folders to matlab path, but it removes the folders from the matlab path everytime the application closes. I want to add that particular folder *permanently* to matlab path, so that I don’t have to add it again everytime i run the application. How can it be done??
Any help is appreciated.I am using addpath to add specified folders to matlab path, but it removes the folders from the matlab path everytime the application closes. I want to add that particular folder *permanently* to matlab path, so that I don’t have to add it again everytime i run the application. How can it be done??
Any help is appreciated. I am using addpath to add specified folders to matlab path, but it removes the folders from the matlab path everytime the application closes. I want to add that particular folder *permanently* to matlab path, so that I don’t have to add it again everytime i run the application. How can it be done??
Any help is appreciated. addpath, genpath MATLAB Answers — New Questions
License Institutional Student Federal?
I have an institutional account and I wanted to know how do I get a license to use MATLAB? I am a student at the Federal Institute of Southern Minas Gerais.I have an institutional account and I wanted to know how do I get a license to use MATLAB? I am a student at the Federal Institute of Southern Minas Gerais. I have an institutional account and I wanted to know how do I get a license to use MATLAB? I am a student at the Federal Institute of Southern Minas Gerais. student MATLAB Answers — New Questions
Error while compiling code with embedded coder support package for STM32
Hello, As part of my master thesis I created a closed loop motor control system with acceleration sensor as input and was in the phase of testing when suddenly i started getting this error below
DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 @Motor_initialization_comp.rsp -o "rtiostream_serial.o" "C:/ProgramData/MATLAB/SupportPackages/R2024a/toolbox/shared/supportpackages/stm32/src/rtiostream_serial.c" C:/ProgramData/MATLAB/SupportPackages/R2024a/toolbox/shared/supportpackages/stm32/src/rtiostream_serial.c:10:10: fatal error: rtiostream.h: No such file or directory 10 | #include "rtiostream.h" | ^~~~~~~~~~~~~~ compilation terminated. gmake: *** [rtiostream_serial.o] Error 1 C:UsersSanathDesktopmaster thesismaster thesis modelMotor_initialization_ert_rtw>echo The make command returned an error of 2 The make command returned an error of 2 C:UsersSanathDesktopmaster thesismaster thesis modelMotor_initialization_ert_rtw>exit /B 1 ### Build procedure for Motor_initialization aborted due to an error.
I have never faced this error and it suddenly started to appear. Moments ago i had compiled a code and it did not have any issues, can anyone suggest how to solve this issue?Hello, As part of my master thesis I created a closed loop motor control system with acceleration sensor as input and was in the phase of testing when suddenly i started getting this error below
DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 @Motor_initialization_comp.rsp -o "rtiostream_serial.o" "C:/ProgramData/MATLAB/SupportPackages/R2024a/toolbox/shared/supportpackages/stm32/src/rtiostream_serial.c" C:/ProgramData/MATLAB/SupportPackages/R2024a/toolbox/shared/supportpackages/stm32/src/rtiostream_serial.c:10:10: fatal error: rtiostream.h: No such file or directory 10 | #include "rtiostream.h" | ^~~~~~~~~~~~~~ compilation terminated. gmake: *** [rtiostream_serial.o] Error 1 C:UsersSanathDesktopmaster thesismaster thesis modelMotor_initialization_ert_rtw>echo The make command returned an error of 2 The make command returned an error of 2 C:UsersSanathDesktopmaster thesismaster thesis modelMotor_initialization_ert_rtw>exit /B 1 ### Build procedure for Motor_initialization aborted due to an error.
I have never faced this error and it suddenly started to appear. Moments ago i had compiled a code and it did not have any issues, can anyone suggest how to solve this issue? Hello, As part of my master thesis I created a closed loop motor control system with acceleration sensor as input and was in the phase of testing when suddenly i started getting this error below
DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 @Motor_initialization_comp.rsp -o "rtiostream_serial.o" "C:/ProgramData/MATLAB/SupportPackages/R2024a/toolbox/shared/supportpackages/stm32/src/rtiostream_serial.c" C:/ProgramData/MATLAB/SupportPackages/R2024a/toolbox/shared/supportpackages/stm32/src/rtiostream_serial.c:10:10: fatal error: rtiostream.h: No such file or directory 10 | #include "rtiostream.h" | ^~~~~~~~~~~~~~ compilation terminated. gmake: *** [rtiostream_serial.o] Error 1 C:UsersSanathDesktopmaster thesismaster thesis modelMotor_initialization_ert_rtw>echo The make command returned an error of 2 The make command returned an error of 2 C:UsersSanathDesktopmaster thesismaster thesis modelMotor_initialization_ert_rtw>exit /B 1 ### Build procedure for Motor_initialization aborted due to an error.
I have never faced this error and it suddenly started to appear. Moments ago i had compiled a code and it did not have any issues, can anyone suggest how to solve this issue? embedded coder, simulink, control, electric_motor_control, digital signal processing, embedded matlab function MATLAB Answers — New Questions
how to set different axis value?
I want to change the axis display value in a contour plot.
xylim = 0.0055 ;
N = 5; x = linspace(-xylim,xylim,N); y = x;
[X,Y] = meshgrid(x,y);
r = (X.^2 + Y.^2); rho = sqrt(r);
f = 0.011 ;
theta = atan(rho./f) ;
CPhi = X./rho; SPhi = Y./rho;
if mod(N,2) == 1
CPhi((N-1)/2+1,(N-1)/2+1) = 1;
SPhi((N-1)/2+1,(N-1)/2+1) = 0;
end
%% Function
n1 = 1;
n2 = 1.5 ;
thetaI = theta;
Th = theta*180/pi;
thetaT = asin((n1./n2).*sin(thetaI));
CTi = cos(thetaI);
CTt = cos(thetaT);
a = (n2.*CTi – n1.*CTt) ;
b = (n2.*CTi + n1.*CTt) ;
c = (n1.*CTi – n2.*CTt) ;
d = (n1.*CTi + n2.*CTt) ;
Rp = a./b;
Rs = c./d;
figure,contourf(X,Y,Rp,20);
Now the x and y axis has value -5 to +5 mm, from the below image we can see. I want to change the axis value from X and Y to the value of the red cross line of the Th value chart(below image) which is a function of X and Y. So new x axis should be [26.5651 14.0362 0 140362 26.5651} and new y axis [26.5651 14.0362 0 140362 26.5651}. can anyone help me please? Thank you.I want to change the axis display value in a contour plot.
xylim = 0.0055 ;
N = 5; x = linspace(-xylim,xylim,N); y = x;
[X,Y] = meshgrid(x,y);
r = (X.^2 + Y.^2); rho = sqrt(r);
f = 0.011 ;
theta = atan(rho./f) ;
CPhi = X./rho; SPhi = Y./rho;
if mod(N,2) == 1
CPhi((N-1)/2+1,(N-1)/2+1) = 1;
SPhi((N-1)/2+1,(N-1)/2+1) = 0;
end
%% Function
n1 = 1;
n2 = 1.5 ;
thetaI = theta;
Th = theta*180/pi;
thetaT = asin((n1./n2).*sin(thetaI));
CTi = cos(thetaI);
CTt = cos(thetaT);
a = (n2.*CTi – n1.*CTt) ;
b = (n2.*CTi + n1.*CTt) ;
c = (n1.*CTi – n2.*CTt) ;
d = (n1.*CTi + n2.*CTt) ;
Rp = a./b;
Rs = c./d;
figure,contourf(X,Y,Rp,20);
Now the x and y axis has value -5 to +5 mm, from the below image we can see. I want to change the axis value from X and Y to the value of the red cross line of the Th value chart(below image) which is a function of X and Y. So new x axis should be [26.5651 14.0362 0 140362 26.5651} and new y axis [26.5651 14.0362 0 140362 26.5651}. can anyone help me please? Thank you. I want to change the axis display value in a contour plot.
xylim = 0.0055 ;
N = 5; x = linspace(-xylim,xylim,N); y = x;
[X,Y] = meshgrid(x,y);
r = (X.^2 + Y.^2); rho = sqrt(r);
f = 0.011 ;
theta = atan(rho./f) ;
CPhi = X./rho; SPhi = Y./rho;
if mod(N,2) == 1
CPhi((N-1)/2+1,(N-1)/2+1) = 1;
SPhi((N-1)/2+1,(N-1)/2+1) = 0;
end
%% Function
n1 = 1;
n2 = 1.5 ;
thetaI = theta;
Th = theta*180/pi;
thetaT = asin((n1./n2).*sin(thetaI));
CTi = cos(thetaI);
CTt = cos(thetaT);
a = (n2.*CTi – n1.*CTt) ;
b = (n2.*CTi + n1.*CTt) ;
c = (n1.*CTi – n2.*CTt) ;
d = (n1.*CTi + n2.*CTt) ;
Rp = a./b;
Rs = c./d;
figure,contourf(X,Y,Rp,20);
Now the x and y axis has value -5 to +5 mm, from the below image we can see. I want to change the axis value from X and Y to the value of the red cross line of the Th value chart(below image) which is a function of X and Y. So new x axis should be [26.5651 14.0362 0 140362 26.5651} and new y axis [26.5651 14.0362 0 140362 26.5651}. can anyone help me please? Thank you. set axis, set axis value, contour plot MATLAB Answers — New Questions
Why is my 3D Projectile Trajectory not being calculated properly?
% Constants
g = 9.81; % gravity
v0 = 50; % initial velocity
% Time
t = linspace(0, 5, 100); % time from 0 to 5 seconds
% Elevation and Azimuth angles
elevation = pi/4; % initial elevation angle (angle above the xz plane)
azimuth = pi/4; % initial azimuth angle (angle from the positive x-axis, counterclockwise)
% Calculate positions
x = v0 * t * cos(elevation) * cos(azimuth);
y = v0 * t * sin(elevation) – 0.5 * g * t.^2;
z = v0 * t * cos(elevation) * sin(azimuth);
% Plot 3D trajectory
figure;
plot3(x, y, z, ‘LineWidth’, 2);
xlabel(‘X’);
ylabel(‘Y’);
zlabel(‘Z’);
title(‘3D Artillery Simulation’);
grid on;% Constants
g = 9.81; % gravity
v0 = 50; % initial velocity
% Time
t = linspace(0, 5, 100); % time from 0 to 5 seconds
% Elevation and Azimuth angles
elevation = pi/4; % initial elevation angle (angle above the xz plane)
azimuth = pi/4; % initial azimuth angle (angle from the positive x-axis, counterclockwise)
% Calculate positions
x = v0 * t * cos(elevation) * cos(azimuth);
y = v0 * t * sin(elevation) – 0.5 * g * t.^2;
z = v0 * t * cos(elevation) * sin(azimuth);
% Plot 3D trajectory
figure;
plot3(x, y, z, ‘LineWidth’, 2);
xlabel(‘X’);
ylabel(‘Y’);
zlabel(‘Z’);
title(‘3D Artillery Simulation’);
grid on; % Constants
g = 9.81; % gravity
v0 = 50; % initial velocity
% Time
t = linspace(0, 5, 100); % time from 0 to 5 seconds
% Elevation and Azimuth angles
elevation = pi/4; % initial elevation angle (angle above the xz plane)
azimuth = pi/4; % initial azimuth angle (angle from the positive x-axis, counterclockwise)
% Calculate positions
x = v0 * t * cos(elevation) * cos(azimuth);
y = v0 * t * sin(elevation) – 0.5 * g * t.^2;
z = v0 * t * cos(elevation) * sin(azimuth);
% Plot 3D trajectory
figure;
plot3(x, y, z, ‘LineWidth’, 2);
xlabel(‘X’);
ylabel(‘Y’);
zlabel(‘Z’);
title(‘3D Artillery Simulation’);
grid on; projectile, physics, azimuth, elevation, launch angle MATLAB Answers — New Questions
Bayesian Time varying coefficient model
(This is more general econometric question) While I am writing a thesis on how the cyclicality of fiscal policy evolve over time in certain countries using Bayesian time varying regression. There are some questions that I would like to ask.
I know that Bayesian regression requires prior distribution (which is chosen by the model maker) and I have no idea what the prior distribution should be. Should I use non-informative prior?
How does Bayesian time varying regression really works? Is it similar to rolling window method in normal regression or is there a method where I can do time varying coefficient model in Bayesian regression?(This is more general econometric question) While I am writing a thesis on how the cyclicality of fiscal policy evolve over time in certain countries using Bayesian time varying regression. There are some questions that I would like to ask.
I know that Bayesian regression requires prior distribution (which is chosen by the model maker) and I have no idea what the prior distribution should be. Should I use non-informative prior?
How does Bayesian time varying regression really works? Is it similar to rolling window method in normal regression or is there a method where I can do time varying coefficient model in Bayesian regression? (This is more general econometric question) While I am writing a thesis on how the cyclicality of fiscal policy evolve over time in certain countries using Bayesian time varying regression. There are some questions that I would like to ask.
I know that Bayesian regression requires prior distribution (which is chosen by the model maker) and I have no idea what the prior distribution should be. Should I use non-informative prior?
How does Bayesian time varying regression really works? Is it similar to rolling window method in normal regression or is there a method where I can do time varying coefficient model in Bayesian regression? bayesian linear regression, time varying coefficient MATLAB Answers — New Questions
When this code is executed, 36 separate windows will open. I want the result to be displayed in a window.
I want the output to be similar to this image.I want the output to be similar to this image. I want the output to be similar to this image. plot, 3d plots, display, plotting MATLAB Answers — New Questions
How to define geographicGrid in matlab code?
I am using following matlab code to extract data but it is giving some error.
img_file = ‘c:data4MARCH24_BAND7_SUBSET.dat’
img = hypercube(img_file);
shapefile = ‘c:dataAchi Khurd.shp’;
S = shaperead(shapefile);
%remove small triangles and squares
coord_lengths = arrayfun(@(s) numel(s.X), S);
not_useful_mask = coord_lengths < 10;
S(not_useful_mask) = [];
polygon = polyshape({S.X}, {S.Y});
% Create a logical mask
[Z,R] = readgeoraster(img_file);
[lat,lon] = geographicGrid(R);
[Lon, Lat] = meshgrid(lon, lat);
logical_mask = reshape(isinterior(polygon, Lon(:), Lat(:)), size(Lon));
% Use the logical mask to extract data
extracted_data = img(logical_mask);
disp(extracted_data);
It is giving following error
Incorrect number or types of inputs or outputs for function geographicGrid.
Error in Test (line 14)
[lat,lon] = geographicGrid(R);
I am attaching the data also in order to run the above mentioned matlab code.
I would be thankful for suggesting me to fix it.
DevaI am using following matlab code to extract data but it is giving some error.
img_file = ‘c:data4MARCH24_BAND7_SUBSET.dat’
img = hypercube(img_file);
shapefile = ‘c:dataAchi Khurd.shp’;
S = shaperead(shapefile);
%remove small triangles and squares
coord_lengths = arrayfun(@(s) numel(s.X), S);
not_useful_mask = coord_lengths < 10;
S(not_useful_mask) = [];
polygon = polyshape({S.X}, {S.Y});
% Create a logical mask
[Z,R] = readgeoraster(img_file);
[lat,lon] = geographicGrid(R);
[Lon, Lat] = meshgrid(lon, lat);
logical_mask = reshape(isinterior(polygon, Lon(:), Lat(:)), size(Lon));
% Use the logical mask to extract data
extracted_data = img(logical_mask);
disp(extracted_data);
It is giving following error
Incorrect number or types of inputs or outputs for function geographicGrid.
Error in Test (line 14)
[lat,lon] = geographicGrid(R);
I am attaching the data also in order to run the above mentioned matlab code.
I would be thankful for suggesting me to fix it.
Deva I am using following matlab code to extract data but it is giving some error.
img_file = ‘c:data4MARCH24_BAND7_SUBSET.dat’
img = hypercube(img_file);
shapefile = ‘c:dataAchi Khurd.shp’;
S = shaperead(shapefile);
%remove small triangles and squares
coord_lengths = arrayfun(@(s) numel(s.X), S);
not_useful_mask = coord_lengths < 10;
S(not_useful_mask) = [];
polygon = polyshape({S.X}, {S.Y});
% Create a logical mask
[Z,R] = readgeoraster(img_file);
[lat,lon] = geographicGrid(R);
[Lon, Lat] = meshgrid(lon, lat);
logical_mask = reshape(isinterior(polygon, Lon(:), Lat(:)), size(Lon));
% Use the logical mask to extract data
extracted_data = img(logical_mask);
disp(extracted_data);
It is giving following error
Incorrect number or types of inputs or outputs for function geographicGrid.
Error in Test (line 14)
[lat,lon] = geographicGrid(R);
I am attaching the data also in order to run the above mentioned matlab code.
I would be thankful for suggesting me to fix it.
Deva how to define geographicgrid in matlab code? MATLAB Answers — New Questions
Saving 3D image after segmentation
I have a 3D image rock that I preformed segmentation on using this code
RA = imread(‘BB258_6_A_2um_1600x3_8bit.tif’);
threshold_calc = multithresh(RA, 2); %two is the number of thresholds so we are expecting to have 3 classes
image_segmented = imquantize(RA, threshold_calc);
imshow(image_segmented , []);
what I want to do is to save the 3D image as tif can you please help meI have a 3D image rock that I preformed segmentation on using this code
RA = imread(‘BB258_6_A_2um_1600x3_8bit.tif’);
threshold_calc = multithresh(RA, 2); %two is the number of thresholds so we are expecting to have 3 classes
image_segmented = imquantize(RA, threshold_calc);
imshow(image_segmented , []);
what I want to do is to save the 3D image as tif can you please help me I have a 3D image rock that I preformed segmentation on using this code
RA = imread(‘BB258_6_A_2um_1600x3_8bit.tif’);
threshold_calc = multithresh(RA, 2); %two is the number of thresholds so we are expecting to have 3 classes
image_segmented = imquantize(RA, threshold_calc);
imshow(image_segmented , []);
what I want to do is to save the 3D image as tif can you please help me save, image processing, image segmentation MATLAB Answers — New Questions
I am recieving an error in creating the solution however it still prints a result.
clc
clear all
close all
%Homework 7 Question 3
Tin=298; %K
Cp=80; %J/(mol K)
CAin=2000; %mol/m^3
k0=10e-7; %m3/(mol min)
Ea_R=5000; %K
rho=1000; %mol/m^3
CA=linspace(2,2000,61);
xA=(CAin-CA)/CAin;
T_sol=zeros(1,length(CA));
k_sol=zeros(1,length(CA));
tau_sol=zeros(1,length(CA));
DHR=-50000; %J/mol exothermic (gets hot)
for i=1:length(CA)
syms T k tau
eqn1=k==k0*exp((-Ea_R)*((1/T)-(1/Tin)));
eqn2=2*k*(CA(i)^2)==(CAin-CA(i))/tau;
eqn3=k*tau*(CA(i))^2*DHR==rho*Cp*(Tin-T);
solution=solve([eqn1,eqn2,eqn3],[T,k,tau]);
T_sol(i)=double(solution.T);
k_sol(i)=double(solution.k);
tau_sol(i)=double(solution.tau);
end
figure(1)
plot(log10(tau_sol),xA,’-bo’);
xlabel(‘log_{10}(tau, min)’)
ylabel(‘x_A’)clc
clear all
close all
%Homework 7 Question 3
Tin=298; %K
Cp=80; %J/(mol K)
CAin=2000; %mol/m^3
k0=10e-7; %m3/(mol min)
Ea_R=5000; %K
rho=1000; %mol/m^3
CA=linspace(2,2000,61);
xA=(CAin-CA)/CAin;
T_sol=zeros(1,length(CA));
k_sol=zeros(1,length(CA));
tau_sol=zeros(1,length(CA));
DHR=-50000; %J/mol exothermic (gets hot)
for i=1:length(CA)
syms T k tau
eqn1=k==k0*exp((-Ea_R)*((1/T)-(1/Tin)));
eqn2=2*k*(CA(i)^2)==(CAin-CA(i))/tau;
eqn3=k*tau*(CA(i))^2*DHR==rho*Cp*(Tin-T);
solution=solve([eqn1,eqn2,eqn3],[T,k,tau]);
T_sol(i)=double(solution.T);
k_sol(i)=double(solution.k);
tau_sol(i)=double(solution.tau);
end
figure(1)
plot(log10(tau_sol),xA,’-bo’);
xlabel(‘log_{10}(tau, min)’)
ylabel(‘x_A’) clc
clear all
close all
%Homework 7 Question 3
Tin=298; %K
Cp=80; %J/(mol K)
CAin=2000; %mol/m^3
k0=10e-7; %m3/(mol min)
Ea_R=5000; %K
rho=1000; %mol/m^3
CA=linspace(2,2000,61);
xA=(CAin-CA)/CAin;
T_sol=zeros(1,length(CA));
k_sol=zeros(1,length(CA));
tau_sol=zeros(1,length(CA));
DHR=-50000; %J/mol exothermic (gets hot)
for i=1:length(CA)
syms T k tau
eqn1=k==k0*exp((-Ea_R)*((1/T)-(1/Tin)));
eqn2=2*k*(CA(i)^2)==(CAin-CA(i))/tau;
eqn3=k*tau*(CA(i))^2*DHR==rho*Cp*(Tin-T);
solution=solve([eqn1,eqn2,eqn3],[T,k,tau]);
T_sol(i)=double(solution.T);
k_sol(i)=double(solution.k);
tau_sol(i)=double(solution.tau);
end
figure(1)
plot(log10(tau_sol),xA,’-bo’);
xlabel(‘log_{10}(tau, min)’)
ylabel(‘x_A’) error, chemical reactor MATLAB Answers — New Questions
using threshold on 3D images to creat mask for training Unet
I am using this code for 128x128x128 3D mirco CT image
% Open input and output files
fid3DOCT = fopen(‘SampleA_128x3_#1.raw’,’r’);
fid3DOCTout = fopen(‘SampleA_128x3_#1_segmented.raw’,’w’);
% Define image dimensions
nx = 128;
ny = 128;
nz = 128;
% Read input image
A = fread(fid3DOCT,nx*ny*nz, ‘uint8’);
A = uint8(reshape(A,nx,ny,nz));
%Define thresholds for segmentation
threshold1 = 48; % Threshold for class 1
threshold2 = 58; % Threshold for class 2
% You can adjust these thresholds as needed
% Apply segmentation
outputImage = zeros(size(A)); % Initialize segmented image
outputImage(A <= threshold1) = 1; % Class 1
outputImage(A > threshold1 & A <= threshold2) = 2; % Class 2
outputImage(A > threshold2) = 3; % Class 3
% Write segmented image to output file
for i = 1:nz
fwrite(fid3DOCTout, outputImage(:,:,i), ‘uint8’);
end
but what I get is a black image
I attached the image I am working on it is actually .raw but I saved as .png so I can attach it
Can you please see why the result is blackI am using this code for 128x128x128 3D mirco CT image
% Open input and output files
fid3DOCT = fopen(‘SampleA_128x3_#1.raw’,’r’);
fid3DOCTout = fopen(‘SampleA_128x3_#1_segmented.raw’,’w’);
% Define image dimensions
nx = 128;
ny = 128;
nz = 128;
% Read input image
A = fread(fid3DOCT,nx*ny*nz, ‘uint8’);
A = uint8(reshape(A,nx,ny,nz));
%Define thresholds for segmentation
threshold1 = 48; % Threshold for class 1
threshold2 = 58; % Threshold for class 2
% You can adjust these thresholds as needed
% Apply segmentation
outputImage = zeros(size(A)); % Initialize segmented image
outputImage(A <= threshold1) = 1; % Class 1
outputImage(A > threshold1 & A <= threshold2) = 2; % Class 2
outputImage(A > threshold2) = 3; % Class 3
% Write segmented image to output file
for i = 1:nz
fwrite(fid3DOCTout, outputImage(:,:,i), ‘uint8’);
end
but what I get is a black image
I attached the image I am working on it is actually .raw but I saved as .png so I can attach it
Can you please see why the result is black I am using this code for 128x128x128 3D mirco CT image
% Open input and output files
fid3DOCT = fopen(‘SampleA_128x3_#1.raw’,’r’);
fid3DOCTout = fopen(‘SampleA_128x3_#1_segmented.raw’,’w’);
% Define image dimensions
nx = 128;
ny = 128;
nz = 128;
% Read input image
A = fread(fid3DOCT,nx*ny*nz, ‘uint8’);
A = uint8(reshape(A,nx,ny,nz));
%Define thresholds for segmentation
threshold1 = 48; % Threshold for class 1
threshold2 = 58; % Threshold for class 2
% You can adjust these thresholds as needed
% Apply segmentation
outputImage = zeros(size(A)); % Initialize segmented image
outputImage(A <= threshold1) = 1; % Class 1
outputImage(A > threshold1 & A <= threshold2) = 2; % Class 2
outputImage(A > threshold2) = 3; % Class 3
% Write segmented image to output file
for i = 1:nz
fwrite(fid3DOCTout, outputImage(:,:,i), ‘uint8’);
end
but what I get is a black image
I attached the image I am working on it is actually .raw but I saved as .png so I can attach it
Can you please see why the result is black image segmentation MATLAB Answers — New Questions
Propblems with plots after installing Matlab 2024a
After installing Matlab 2024a I have encountered following problem
I create any plot command, e.g.:
>> t = -3:0.1:3;
>> y = t.^2;
>> figure, plot(t,y)
After moving the mouse pointer over the axes in the figure, I recieve th following massage:
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.interaction.actions.Linger/startTimer
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.interaction.actions.Linger/startTimer
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Warning: Error occurred while executing the listener callback for event ButtonExited defined for class
matlab.graphics.primitive.canvas.JavaCanvas:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.controls.ToolbarController/createTooltipTimer
Error in matlab.graphics.controls.ToolbarController/get.ToolTipTimer
Error in matlab.graphics.controls.ToolbarController/doButtonUnhover
Error in matlab.graphics.controls.ToolbarController/handleMouseExited
Error in matlab.graphics.controls.DesktopToolbarController/handleMouseExited
Error in matlab.graphics.controls.ToolbarController>@(e,d)obj.handleMouseExited(e,d)
Similar problem appears when i try e.g. copy the figure into the clipboard:
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.interaction.actions.Linger/startTimer
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Error in print (line 36)
drawnow; % give changes a chance to be processed
Error in matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
print(argsToPrint{:});
Error in matlab.graphics.internal.copyFigureHelper (line 16)
doJavaFigureCopy(hFigure);
Error in editmenufcn (line 68)
matlab.graphics.internal.copyFigureHelper(hfig)
> In print (line 36)
In matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
In matlab.graphics.internal.copyFigureHelper (line 16)
In editmenufcn (line 68)
Warning: Error occurred while executing the listener callback for event ButtonExited defined for class
matlab.graphics.primitive.canvas.JavaCanvas:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.controls.ToolbarController/createTooltipTimer
Error in matlab.graphics.controls.ToolbarController/get.ToolTipTimer
Error in matlab.graphics.controls.ToolbarController/doButtonUnhover
Error in matlab.graphics.controls.ToolbarController/handleMouseExited
Error in matlab.graphics.controls.DesktopToolbarController/handleMouseExited
Error in matlab.graphics.controls.ToolbarController>@(e,d)obj.handleMouseExited(e,d)
Error in alternatePrintPath
Error in print (line 90)
pj = alternatePrintPath(pj);
Error in matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
print(argsToPrint{:});
Error in matlab.graphics.internal.copyFigureHelper (line 16)
doJavaFigureCopy(hFigure);
Error in editmenufcn (line 68)
matlab.graphics.internal.copyFigureHelper(hfig)
> In alternatePrintPath
In print (line 90)
In matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
In matlab.graphics.internal.copyFigureHelper (line 16)
In editmenufcn (line 68)
Can you tell me what is wrong?
I use Windows 10 Enterprise LTSC, 64-bit, version 1809, build 17763.5696
Thank you for the answer, with best regards,
Roman Vitek.After installing Matlab 2024a I have encountered following problem
I create any plot command, e.g.:
>> t = -3:0.1:3;
>> y = t.^2;
>> figure, plot(t,y)
After moving the mouse pointer over the axes in the figure, I recieve th following massage:
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.interaction.actions.Linger/startTimer
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.interaction.actions.Linger/startTimer
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Warning: Error occurred while executing the listener callback for event ButtonExited defined for class
matlab.graphics.primitive.canvas.JavaCanvas:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.controls.ToolbarController/createTooltipTimer
Error in matlab.graphics.controls.ToolbarController/get.ToolTipTimer
Error in matlab.graphics.controls.ToolbarController/doButtonUnhover
Error in matlab.graphics.controls.ToolbarController/handleMouseExited
Error in matlab.graphics.controls.DesktopToolbarController/handleMouseExited
Error in matlab.graphics.controls.ToolbarController>@(e,d)obj.handleMouseExited(e,d)
Similar problem appears when i try e.g. copy the figure into the clipboard:
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.interaction.actions.Linger/startTimer
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Error in print (line 36)
drawnow; % give changes a chance to be processed
Error in matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
print(argsToPrint{:});
Error in matlab.graphics.internal.copyFigureHelper (line 16)
doJavaFigureCopy(hFigure);
Error in editmenufcn (line 68)
matlab.graphics.internal.copyFigureHelper(hfig)
> In print (line 36)
In matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
In matlab.graphics.internal.copyFigureHelper (line 16)
In editmenufcn (line 68)
Warning: Error occurred while executing the listener callback for event ButtonExited defined for class
matlab.graphics.primitive.canvas.JavaCanvas:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.controls.ToolbarController/createTooltipTimer
Error in matlab.graphics.controls.ToolbarController/get.ToolTipTimer
Error in matlab.graphics.controls.ToolbarController/doButtonUnhover
Error in matlab.graphics.controls.ToolbarController/handleMouseExited
Error in matlab.graphics.controls.DesktopToolbarController/handleMouseExited
Error in matlab.graphics.controls.ToolbarController>@(e,d)obj.handleMouseExited(e,d)
Error in alternatePrintPath
Error in print (line 90)
pj = alternatePrintPath(pj);
Error in matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
print(argsToPrint{:});
Error in matlab.graphics.internal.copyFigureHelper (line 16)
doJavaFigureCopy(hFigure);
Error in editmenufcn (line 68)
matlab.graphics.internal.copyFigureHelper(hfig)
> In alternatePrintPath
In print (line 90)
In matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
In matlab.graphics.internal.copyFigureHelper (line 16)
In editmenufcn (line 68)
Can you tell me what is wrong?
I use Windows 10 Enterprise LTSC, 64-bit, version 1809, build 17763.5696
Thank you for the answer, with best regards,
Roman Vitek. After installing Matlab 2024a I have encountered following problem
I create any plot command, e.g.:
>> t = -3:0.1:3;
>> y = t.^2;
>> figure, plot(t,y)
After moving the mouse pointer over the axes in the figure, I recieve th following massage:
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.interaction.actions.Linger/startTimer
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.interaction.actions.Linger/startTimer
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Warning: Error occurred while executing the listener callback for event ButtonExited defined for class
matlab.graphics.primitive.canvas.JavaCanvas:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.controls.ToolbarController/createTooltipTimer
Error in matlab.graphics.controls.ToolbarController/get.ToolTipTimer
Error in matlab.graphics.controls.ToolbarController/doButtonUnhover
Error in matlab.graphics.controls.ToolbarController/handleMouseExited
Error in matlab.graphics.controls.DesktopToolbarController/handleMouseExited
Error in matlab.graphics.controls.ToolbarController>@(e,d)obj.handleMouseExited(e,d)
Similar problem appears when i try e.g. copy the figure into the clipboard:
Warning: Error occurred while executing the listener callback for event WindowMouseMotion defined for class matlab.ui.Figure:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.interaction.actions.Linger/startTimer
Error in matlab.graphics.interaction.actions.Linger/motionCallback
Error in matlab.graphics.interaction.actions.Linger
Error in print (line 36)
drawnow; % give changes a chance to be processed
Error in matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
print(argsToPrint{:});
Error in matlab.graphics.internal.copyFigureHelper (line 16)
doJavaFigureCopy(hFigure);
Error in editmenufcn (line 68)
matlab.graphics.internal.copyFigureHelper(hfig)
> In print (line 36)
In matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
In matlab.graphics.internal.copyFigureHelper (line 16)
In editmenufcn (line 68)
Warning: Error occurred while executing the listener callback for event ButtonExited defined for class
matlab.graphics.primitive.canvas.JavaCanvas:
Undefined function ‘timer’ for input arguments of type ‘char’.
Error in matlab.graphics.controls.ToolbarController/createTooltipTimer
Error in matlab.graphics.controls.ToolbarController/get.ToolTipTimer
Error in matlab.graphics.controls.ToolbarController/doButtonUnhover
Error in matlab.graphics.controls.ToolbarController/handleMouseExited
Error in matlab.graphics.controls.DesktopToolbarController/handleMouseExited
Error in matlab.graphics.controls.ToolbarController>@(e,d)obj.handleMouseExited(e,d)
Error in alternatePrintPath
Error in print (line 90)
pj = alternatePrintPath(pj);
Error in matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
print(argsToPrint{:});
Error in matlab.graphics.internal.copyFigureHelper (line 16)
doJavaFigureCopy(hFigure);
Error in editmenufcn (line 68)
matlab.graphics.internal.copyFigureHelper(hfig)
> In alternatePrintPath
In print (line 90)
In matlab.graphics.internal.copyFigureHelper>doJavaFigureCopy (line 173)
In matlab.graphics.internal.copyFigureHelper (line 16)
In editmenufcn (line 68)
Can you tell me what is wrong?
I use Windows 10 Enterprise LTSC, 64-bit, version 1809, build 17763.5696
Thank you for the answer, with best regards,
Roman Vitek. 2dplot, error MATLAB Answers — New Questions
Calculating the radius of a link budget
Hi there, how would I calculate the cell radius of a link budget?
I have a given link budget but just on the uplink. Would I need to use the satellite link budget app within MATLAB or is there a way to code this?
Thanks in advance,
P.S. not a beg for code, just a point in the right direction would be helpful please?Hi there, how would I calculate the cell radius of a link budget?
I have a given link budget but just on the uplink. Would I need to use the satellite link budget app within MATLAB or is there a way to code this?
Thanks in advance,
P.S. not a beg for code, just a point in the right direction would be helpful please? Hi there, how would I calculate the cell radius of a link budget?
I have a given link budget but just on the uplink. Would I need to use the satellite link budget app within MATLAB or is there a way to code this?
Thanks in advance,
P.S. not a beg for code, just a point in the right direction would be helpful please? uplink, link budget MATLAB Answers — New Questions
listening to the creation/deletion of a file with specific name.
Hi,
I’m wondering if it is possible somehow to listen to the creation/deletion of a file with an specific name. I know in Windows one has the option of controling .NET events, but I need a similar functionality also in Linux and Mac… I know I can create timers that scan continuously the file system, but this solution is rather inelegant and seems to compromise the performance of my code, so I’m interested in a solution more oriented to actual listeners… Any ideas?
Thanks in advance,
DanielHi,
I’m wondering if it is possible somehow to listen to the creation/deletion of a file with an specific name. I know in Windows one has the option of controling .NET events, but I need a similar functionality also in Linux and Mac… I know I can create timers that scan continuously the file system, but this solution is rather inelegant and seems to compromise the performance of my code, so I’m interested in a solution more oriented to actual listeners… Any ideas?
Thanks in advance,
Daniel Hi,
I’m wondering if it is possible somehow to listen to the creation/deletion of a file with an specific name. I know in Windows one has the option of controling .NET events, but I need a similar functionality also in Linux and Mac… I know I can create timers that scan continuously the file system, but this solution is rather inelegant and seems to compromise the performance of my code, so I’m interested in a solution more oriented to actual listeners… Any ideas?
Thanks in advance,
Daniel listener, file system, system.io.filesystemwatcher, linux, files MATLAB Answers — New Questions
Can anyone share MR damper model for 2 DOF suspension model?
Hello Everyone,
I am working on Magnetorheological Fluid Damper for vehicle suspension. My Model is not working. I have tried my model with different road input profiles with a CSC controller for the voltage. But the model does not show
the increase in the force with the increase of voltage.
Can anyone help me with this?
Thank you very much.
Regards
BaigHello Everyone,
I am working on Magnetorheological Fluid Damper for vehicle suspension. My Model is not working. I have tried my model with different road input profiles with a CSC controller for the voltage. But the model does not show
the increase in the force with the increase of voltage.
Can anyone help me with this?
Thank you very much.
Regards
Baig Hello Everyone,
I am working on Magnetorheological Fluid Damper for vehicle suspension. My Model is not working. I have tried my model with different road input profiles with a CSC controller for the voltage. But the model does not show
the increase in the force with the increase of voltage.
Can anyone help me with this?
Thank you very much.
Regards
Baig mr damper, magnetorheologica fluid damper MATLAB Answers — New Questions
Solving ODE using laplace
This is the question I’m struggling on
Using the Laplace transform find the solution for the following ODE:
d^2/dt(y(t)) + 16y(t) = 16[1(t-3) -1(t)]
initial conditions:
y(0) = 0
dy(t)/dt = 0
I have to solve the ODE with laplace and with inverse laplace
Save the inverse laplace in y_sol.
This is what I wrote but it gives me the wrong answer:
syms t s y(t) Y X
y0 = 0;
dot_y0 = 0;
dot_y = diff(y,t);
ddot_y = diff(dot_y,t);
ode = ddot_y + 16*y == 16*(1*(t-3)-1*(t))
Y1 = laplace(ode,t,s)
ysol1 = subs(Y1,laplace(y,t,s),X)
ysol2 = subs(ysol1,y(0),y0)
ysol3 = subs(ysol2, subs(diff(y(t), t), t, 0), dot_y0)
ysol = solve(ysol3, X)
Y = simplify(expand(ysol))
y_sol = ilaplace(Y)This is the question I’m struggling on
Using the Laplace transform find the solution for the following ODE:
d^2/dt(y(t)) + 16y(t) = 16[1(t-3) -1(t)]
initial conditions:
y(0) = 0
dy(t)/dt = 0
I have to solve the ODE with laplace and with inverse laplace
Save the inverse laplace in y_sol.
This is what I wrote but it gives me the wrong answer:
syms t s y(t) Y X
y0 = 0;
dot_y0 = 0;
dot_y = diff(y,t);
ddot_y = diff(dot_y,t);
ode = ddot_y + 16*y == 16*(1*(t-3)-1*(t))
Y1 = laplace(ode,t,s)
ysol1 = subs(Y1,laplace(y,t,s),X)
ysol2 = subs(ysol1,y(0),y0)
ysol3 = subs(ysol2, subs(diff(y(t), t), t, 0), dot_y0)
ysol = solve(ysol3, X)
Y = simplify(expand(ysol))
y_sol = ilaplace(Y) This is the question I’m struggling on
Using the Laplace transform find the solution for the following ODE:
d^2/dt(y(t)) + 16y(t) = 16[1(t-3) -1(t)]
initial conditions:
y(0) = 0
dy(t)/dt = 0
I have to solve the ODE with laplace and with inverse laplace
Save the inverse laplace in y_sol.
This is what I wrote but it gives me the wrong answer:
syms t s y(t) Y X
y0 = 0;
dot_y0 = 0;
dot_y = diff(y,t);
ddot_y = diff(dot_y,t);
ode = ddot_y + 16*y == 16*(1*(t-3)-1*(t))
Y1 = laplace(ode,t,s)
ysol1 = subs(Y1,laplace(y,t,s),X)
ysol2 = subs(ysol1,y(0),y0)
ysol3 = subs(ysol2, subs(diff(y(t), t), t, 0), dot_y0)
ysol = solve(ysol3, X)
Y = simplify(expand(ysol))
y_sol = ilaplace(Y) ode MATLAB Answers — New Questions
Non linear mixed effects model – Fitting Time Activity Curve
Hello MATLAB users!
I’m facing some issues with fitting the data I have in a excel spreadsheet. The Excel table contains 16 columns and 150 rows, excluding the header. From left to right, the columns are Times, Kidneys_P1, Kidneys_P2, Kidneys_P3, Kidneys_P4, Kidneys_P5, Tumor_P1, Tumor_P2, Tumor_P3, Tumor_P4, Tumor_P5, Blood_P1, Blood_P2, Blood_P3, Blood_P4, Blood_P5. The values represent the administered activity (radioactive activity) in patients. I want to fit the curves using a non-linear mixed-effects model, using the following equation:
model = [A1*e^-(λ1+λ1_phys)*t] + [A2*e^-(λ_phys)*t] – [A3*e^-(λ_2+λ_phys)*t] – (A1+A2-A3)*e^-(λ_bc+λ_phys)*t
where A1, A2, and A3 are the coefficients of the respective exponential terms with values ≥ 0, λ1 and λ2 are biological rate constants with values ≥ 0, λ_bc is the rate of blood circulation approximated as λbc = ln(2)/1min, and λphys represents the radionuclide physical decay constant = ln(2)/6.7*24*60 = 7.18E-5 min-1.
Here is a piece of my MATLAB code:
% Import Excel Data
clc, clear all, format compact
TAC_data = readtable("CorrectedFile.xlsx");
% Extract the times and activity data for each organ and patient
times = TAC_data{:,1};
kidneys = TAC_data(:, 2:6);
tumor = TAC_data(:, 7:11);
blood = TAC_data(:, 12:16);
% Initial guess
initialGuess = [0.5, 0.5, 0.5, 0.1, 0.1, 7.18E-5, 0.30];
% Model function
model = @(params, times) (params(1) * exp(-(params(4) + params(6)) * times)) + …
(params(2) * exp(-params(6) * times)) – …
(params(3) * exp(-(params(5) + params(6)) * times)) – …
(params(1) + params(2) – params(3)) * exp(-(params(7) + params(6)) * times);
% Iterate over each organ and perform the curve fitting for all patients within that organ
organs = {‘Kidneys’, ‘Tumor’, ‘Blood’};
patients = {‘P1’, ‘P2’, ‘P3’, ‘P4’, ‘P5’};
optimized_parameters = cell(length(organs), length(patients));
for i = 1:length(organs)
organ = organs{i};
% Select the data for the current organ
organ_data = TAC_data(:, (i-1)*5 + 2 : i*5 + 1);
% Stack the columns of organ data into a matrix
stacked_organ_data = table2array(organ_data);
% Perform curve fitting for each combination of organ and patient
for j = 1:length(patients)
% Select the activity data for the current patient
activity = stacked_organ_data(:, j);
% Create the grouping variable for this patient
patient_group = repmat(j, size(activity)); % Repeat patient index
% Perform curve fitting for the current organ and patient
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
% Store the optimized parameters
optimized_parameters{i, j} = optimized_params;
% Print the optimized parameters
fprintf(‘Optimized parameters for %s – %s:n’, organ, patients{j});
disp(optimized_params);
end
end
In the line "Perform curve fitting" I am using the nlmefitsa tool, however, I ran the code and got the following error. Sorry in advance, I don`t know how to put the error text in red.
Error using nlmefitsa>modelcaller
Model function has returned Inf or NaN values.
Error in nlmefitsa>@(p,x,v,e)modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e) (line 602)
structural_model = @(p,x,v,e) modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e);
Error in nlmefitsa>saem_randstep (line 2120)
[f,g] = structural_model(phiMc,XM,VM,errmod);
Error in nlmefitsa/onefit (line 692)
[f,g,etaMc] = saem_randstep(ind_eta,eta0,vk2,myrandn,cholfact,…
Error in nlmefitsa (line 470)
[stop,betas(:,jrep),Gj,statsj,b_hat(idxRandPerm,uId,jrep)] = onefit(beta0(:,jbeta));
Error in test (line 43)
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
I think the error can be related to the initial guess, but I don’t know how to fix it.
Any help is welcome. I appreciate it if anyone can assist me!Hello MATLAB users!
I’m facing some issues with fitting the data I have in a excel spreadsheet. The Excel table contains 16 columns and 150 rows, excluding the header. From left to right, the columns are Times, Kidneys_P1, Kidneys_P2, Kidneys_P3, Kidneys_P4, Kidneys_P5, Tumor_P1, Tumor_P2, Tumor_P3, Tumor_P4, Tumor_P5, Blood_P1, Blood_P2, Blood_P3, Blood_P4, Blood_P5. The values represent the administered activity (radioactive activity) in patients. I want to fit the curves using a non-linear mixed-effects model, using the following equation:
model = [A1*e^-(λ1+λ1_phys)*t] + [A2*e^-(λ_phys)*t] – [A3*e^-(λ_2+λ_phys)*t] – (A1+A2-A3)*e^-(λ_bc+λ_phys)*t
where A1, A2, and A3 are the coefficients of the respective exponential terms with values ≥ 0, λ1 and λ2 are biological rate constants with values ≥ 0, λ_bc is the rate of blood circulation approximated as λbc = ln(2)/1min, and λphys represents the radionuclide physical decay constant = ln(2)/6.7*24*60 = 7.18E-5 min-1.
Here is a piece of my MATLAB code:
% Import Excel Data
clc, clear all, format compact
TAC_data = readtable("CorrectedFile.xlsx");
% Extract the times and activity data for each organ and patient
times = TAC_data{:,1};
kidneys = TAC_data(:, 2:6);
tumor = TAC_data(:, 7:11);
blood = TAC_data(:, 12:16);
% Initial guess
initialGuess = [0.5, 0.5, 0.5, 0.1, 0.1, 7.18E-5, 0.30];
% Model function
model = @(params, times) (params(1) * exp(-(params(4) + params(6)) * times)) + …
(params(2) * exp(-params(6) * times)) – …
(params(3) * exp(-(params(5) + params(6)) * times)) – …
(params(1) + params(2) – params(3)) * exp(-(params(7) + params(6)) * times);
% Iterate over each organ and perform the curve fitting for all patients within that organ
organs = {‘Kidneys’, ‘Tumor’, ‘Blood’};
patients = {‘P1’, ‘P2’, ‘P3’, ‘P4’, ‘P5’};
optimized_parameters = cell(length(organs), length(patients));
for i = 1:length(organs)
organ = organs{i};
% Select the data for the current organ
organ_data = TAC_data(:, (i-1)*5 + 2 : i*5 + 1);
% Stack the columns of organ data into a matrix
stacked_organ_data = table2array(organ_data);
% Perform curve fitting for each combination of organ and patient
for j = 1:length(patients)
% Select the activity data for the current patient
activity = stacked_organ_data(:, j);
% Create the grouping variable for this patient
patient_group = repmat(j, size(activity)); % Repeat patient index
% Perform curve fitting for the current organ and patient
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
% Store the optimized parameters
optimized_parameters{i, j} = optimized_params;
% Print the optimized parameters
fprintf(‘Optimized parameters for %s – %s:n’, organ, patients{j});
disp(optimized_params);
end
end
In the line "Perform curve fitting" I am using the nlmefitsa tool, however, I ran the code and got the following error. Sorry in advance, I don`t know how to put the error text in red.
Error using nlmefitsa>modelcaller
Model function has returned Inf or NaN values.
Error in nlmefitsa>@(p,x,v,e)modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e) (line 602)
structural_model = @(p,x,v,e) modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e);
Error in nlmefitsa>saem_randstep (line 2120)
[f,g] = structural_model(phiMc,XM,VM,errmod);
Error in nlmefitsa/onefit (line 692)
[f,g,etaMc] = saem_randstep(ind_eta,eta0,vk2,myrandn,cholfact,…
Error in nlmefitsa (line 470)
[stop,betas(:,jrep),Gj,statsj,b_hat(idxRandPerm,uId,jrep)] = onefit(beta0(:,jbeta));
Error in test (line 43)
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
I think the error can be related to the initial guess, but I don’t know how to fix it.
Any help is welcome. I appreciate it if anyone can assist me! Hello MATLAB users!
I’m facing some issues with fitting the data I have in a excel spreadsheet. The Excel table contains 16 columns and 150 rows, excluding the header. From left to right, the columns are Times, Kidneys_P1, Kidneys_P2, Kidneys_P3, Kidneys_P4, Kidneys_P5, Tumor_P1, Tumor_P2, Tumor_P3, Tumor_P4, Tumor_P5, Blood_P1, Blood_P2, Blood_P3, Blood_P4, Blood_P5. The values represent the administered activity (radioactive activity) in patients. I want to fit the curves using a non-linear mixed-effects model, using the following equation:
model = [A1*e^-(λ1+λ1_phys)*t] + [A2*e^-(λ_phys)*t] – [A3*e^-(λ_2+λ_phys)*t] – (A1+A2-A3)*e^-(λ_bc+λ_phys)*t
where A1, A2, and A3 are the coefficients of the respective exponential terms with values ≥ 0, λ1 and λ2 are biological rate constants with values ≥ 0, λ_bc is the rate of blood circulation approximated as λbc = ln(2)/1min, and λphys represents the radionuclide physical decay constant = ln(2)/6.7*24*60 = 7.18E-5 min-1.
Here is a piece of my MATLAB code:
% Import Excel Data
clc, clear all, format compact
TAC_data = readtable("CorrectedFile.xlsx");
% Extract the times and activity data for each organ and patient
times = TAC_data{:,1};
kidneys = TAC_data(:, 2:6);
tumor = TAC_data(:, 7:11);
blood = TAC_data(:, 12:16);
% Initial guess
initialGuess = [0.5, 0.5, 0.5, 0.1, 0.1, 7.18E-5, 0.30];
% Model function
model = @(params, times) (params(1) * exp(-(params(4) + params(6)) * times)) + …
(params(2) * exp(-params(6) * times)) – …
(params(3) * exp(-(params(5) + params(6)) * times)) – …
(params(1) + params(2) – params(3)) * exp(-(params(7) + params(6)) * times);
% Iterate over each organ and perform the curve fitting for all patients within that organ
organs = {‘Kidneys’, ‘Tumor’, ‘Blood’};
patients = {‘P1’, ‘P2’, ‘P3’, ‘P4’, ‘P5’};
optimized_parameters = cell(length(organs), length(patients));
for i = 1:length(organs)
organ = organs{i};
% Select the data for the current organ
organ_data = TAC_data(:, (i-1)*5 + 2 : i*5 + 1);
% Stack the columns of organ data into a matrix
stacked_organ_data = table2array(organ_data);
% Perform curve fitting for each combination of organ and patient
for j = 1:length(patients)
% Select the activity data for the current patient
activity = stacked_organ_data(:, j);
% Create the grouping variable for this patient
patient_group = repmat(j, size(activity)); % Repeat patient index
% Perform curve fitting for the current organ and patient
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
% Store the optimized parameters
optimized_parameters{i, j} = optimized_params;
% Print the optimized parameters
fprintf(‘Optimized parameters for %s – %s:n’, organ, patients{j});
disp(optimized_params);
end
end
In the line "Perform curve fitting" I am using the nlmefitsa tool, however, I ran the code and got the following error. Sorry in advance, I don`t know how to put the error text in red.
Error using nlmefitsa>modelcaller
Model function has returned Inf or NaN values.
Error in nlmefitsa>@(p,x,v,e)modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e) (line 602)
structural_model = @(p,x,v,e) modelcaller(fvc,vect,modelfun,IdM,transphi(p),x,v,e);
Error in nlmefitsa>saem_randstep (line 2120)
[f,g] = structural_model(phiMc,XM,VM,errmod);
Error in nlmefitsa/onefit (line 692)
[f,g,etaMc] = saem_randstep(ind_eta,eta0,vk2,myrandn,cholfact,…
Error in nlmefitsa (line 470)
[stop,betas(:,jrep),Gj,statsj,b_hat(idxRandPerm,uId,jrep)] = onefit(beta0(:,jbeta));
Error in test (line 43)
[optimized_params, ~, ~] = nlmefitsa(times, activity, patient_group, [], model, initialGuess);
I think the error can be related to the initial guess, but I don’t know how to fix it.
Any help is welcome. I appreciate it if anyone can assist me! non linear mixed effects, curve fitting MATLAB Answers — New Questions
Simscape Multibody: external force and motion inputs, reaction torque sensing.
Hello everyone!
I’m using simscape multibody and I’m studying a simple 2-links multibody system.
The frame (1st link) is connected to the 2nd one through a revolute joint coupling.
I’d like to apply:
a vertical external force (Fext) at the end of the 2nd link
vary the angle-joint position (theta) from 45° to 60° (therefore, apply a vector, as the angle input, to the joint in Simscape)
The purpose of this study is to sense the Reaction torque (T) at the joint that balances the Fext so that the system stays sill (for every configuration of theta).
How can I do it using Simscape multibody’s blocks?
Thank you very much in advance :)Hello everyone!
I’m using simscape multibody and I’m studying a simple 2-links multibody system.
The frame (1st link) is connected to the 2nd one through a revolute joint coupling.
I’d like to apply:
a vertical external force (Fext) at the end of the 2nd link
vary the angle-joint position (theta) from 45° to 60° (therefore, apply a vector, as the angle input, to the joint in Simscape)
The purpose of this study is to sense the Reaction torque (T) at the joint that balances the Fext so that the system stays sill (for every configuration of theta).
How can I do it using Simscape multibody’s blocks?
Thank you very much in advance 🙂 Hello everyone!
I’m using simscape multibody and I’m studying a simple 2-links multibody system.
The frame (1st link) is connected to the 2nd one through a revolute joint coupling.
I’d like to apply:
a vertical external force (Fext) at the end of the 2nd link
vary the angle-joint position (theta) from 45° to 60° (therefore, apply a vector, as the angle input, to the joint in Simscape)
The purpose of this study is to sense the Reaction torque (T) at the joint that balances the Fext so that the system stays sill (for every configuration of theta).
How can I do it using Simscape multibody’s blocks?
Thank you very much in advance 🙂 simscape, multibody, torque, force, position, sensing, input, joint, angle, variable, reaction MATLAB Answers — New Questions
Simulink rocket simulation, the scope is not working
Hello guys,
It’s urgent, I have rocket simulation, takeoff and landing, the problem is that the simulation is working and in the display I get values, but when I enter the scope there is no graph that show. I will share with you the simulink and matlab code files. can you please correct the problem and send me the working one.
here are the parameters
as you can see in the display there are values but nothing in the scope.
Please can you fix it thank you.Hello guys,
It’s urgent, I have rocket simulation, takeoff and landing, the problem is that the simulation is working and in the display I get values, but when I enter the scope there is no graph that show. I will share with you the simulink and matlab code files. can you please correct the problem and send me the working one.
here are the parameters
as you can see in the display there are values but nothing in the scope.
Please can you fix it thank you. Hello guys,
It’s urgent, I have rocket simulation, takeoff and landing, the problem is that the simulation is working and in the display I get values, but when I enter the scope there is no graph that show. I will share with you the simulink and matlab code files. can you please correct the problem and send me the working one.
here are the parameters
as you can see in the display there are values but nothing in the scope.
Please can you fix it thank you. simulink, rocket, control, matlab, scope MATLAB Answers — New Questions