Tag Archives: matlab
I need help using the corrcoef function to calculate PRx (pressure reactivity index)
Hi everyone! I need to calculate PRx (pressure reactivity index) using ICP (intracranial pressure) and mean ABP (mean arterial blood pressure) data. PRx is known as "pressure reactivity index is calculated as the degree of statistical correlation between the slow wave components of mean arterial pressure (ABP) and intracranial pressure (ICP)". I need to do this in order to calculate a different hypothetical reactivity index. I have PRx data- so my idea was to use the given PRx data and compare it to the calculated PRx data to ensure it is correct.
This is the script to display the PRx data that was given to me:
%PRx_display
% Load PRx data from MAT file
load(‘PRx,data_part1of1’);
PRx_values = measurement_data;
disp(‘PRx Values:’);
disp(PRx_values);
% Plot PRx values
figure;
plot(PRx_values);
xlabel(‘Time’);
ylabel(‘PRx Value’);
title(‘PRx’);
grid on;
% Calculate average PRx
average_PRx = mean(PRx_values);
% Display average PRx
fprintf(‘Average PRx: %.4f\n’, average_PRx);
This is the script I am trying to calculate PRx with:
%PRx_calc
% Load ICP and MAP data
load("ICP,data_part1of1");
ICP_time_vector = round(time_vector); % Assuming time_vector in ICP file
ICP_data = measurement_data;
load("ABP,mean,data_part1of1");
ABP_time_vector = round(time_vector); % Assuming time_vector in ABP file
ABP_data = measurement_data;
% Remove duplicate time points from ICP
[ICP_time_vector, uniqueIdx] = unique(ICP_time_vector);
ICP_data = ICP_data(uniqueIdx);
% Remove duplicate time points from ABP
[ABP_time_vector, uniqueIdx] = unique(ABP_time_vector);
ABP_data = ABP_data(uniqueIdx);
% Ensure consistent dimensions
if length(ICP_time_vector) ~= length(ICP_data)
error(‘ICP_time_vector and ICP_data have different lengths’);
end
if length(ABP_time_vector) ~= length(ABP_data)
error(‘ABP_time_vector and ABP_data have different lengths’);
end
% Interpolating ABP to match ICP time vector
if ~isequal(ICP_time_vector, ABP_time_vector)
ABP_data = interp1(ABP_time_vector, ABP_data, ICP_time_vector, ‘linear’, ‘extrap’);
end
% Combine ICP data and aligned ABP data
ICP = [ICP_time_vector(:), ICP_data(:)]; % Ensure column vectors
ABP = [ICP_time_vector(:), ABP_data(:)]; % ABP_data is now interpolated to match ICP_time_vector
% Parameters
windowSize = 30 * 10; % 30 windows of 10 seconds
stepSize = 60; % Update every 60 seconds
n = length(ICP_time_vector); % Number of data points
% Preallocate PRx array
PRx = NaN(floor((n – windowSize) / stepSize) + 1, 1);
% Compute moving correlation coefficient
for i = 1:stepSize:(n – windowSize + 1)
% Extract current window of data
windowICP = ICP(i:i + windowSize – 1, 2);
windowABP = ABP(i:i + windowSize – 1, 2);
% Calculate correlation coefficient for the current window
R = corrcoef(windowICP, windowABP);
% Store PRx (correlation coefficient of ICP and ABP)
PRx(floor(i / stepSize) + 1) = R(1, 2);
end
% Calculate average PRx ignoring NaN values
averagePRx = sum(PRx, ‘omitnan’) / sum(~isnan(PRx));
% Display average PRx in the command window
fprintf(‘Average PRx: %.4f\n’, averagePRx);
% Plot PRx vs Time in minutes
figure;
plot((0:length(PRx)-1)*stepSize/60, PRx); % Convert to minutes
title(‘PRx vs Time’);
xlabel(‘Time (minutes)’);
ylabel(‘PRx Values’);
I thought the calculation script would work, but it doesn’t. For instance, for a certain set of data, PRx_calc.m gives me an average PRx value of 0.32, while PRx_display.m gives me 0.52. The trend of the plots look the same, but the PRx_calc.m’s for some reason looks shifted down and distorted a little bit. I am looking for help with the way I am using the corrcoef function and general debugging help.
Here are the first 20 values of each type of data: First 20 values of
ICP: 10 10 10 10 11 11 11 11 10 11 10 11 11 11 11 11 10 11 11 11
First 20 values of
ABP: 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89
First 20 calculated
PRx values: NaN NaN NaN NaN NaN NaN -0.0838 -0.2111 -0.0586 0.1704 0.4276 0.3193 0.3417 0.4128 0.5488 0.4790 0.5207 0.6822 0.7107 0.5235
Average PRx: 0.3209
The PRx_calc script, which produces the above values, should produce the given PRx values(below).
First 20 PRx Values: 0.6150 0.5996 0.6010 0.6276 0.7499 0.4495 0.4488 0.4492 0.5078 0.7263 0.7290 0.7343 0.7490 0.7561 0.6997 0.4609 0.2567 0.5935 0.7317 0.6666
Average PRx: 0.5247
Please let me know if there is anything else I should add, more data points, graphs, etc. Thank you!Hi everyone! I need to calculate PRx (pressure reactivity index) using ICP (intracranial pressure) and mean ABP (mean arterial blood pressure) data. PRx is known as "pressure reactivity index is calculated as the degree of statistical correlation between the slow wave components of mean arterial pressure (ABP) and intracranial pressure (ICP)". I need to do this in order to calculate a different hypothetical reactivity index. I have PRx data- so my idea was to use the given PRx data and compare it to the calculated PRx data to ensure it is correct.
This is the script to display the PRx data that was given to me:
%PRx_display
% Load PRx data from MAT file
load(‘PRx,data_part1of1’);
PRx_values = measurement_data;
disp(‘PRx Values:’);
disp(PRx_values);
% Plot PRx values
figure;
plot(PRx_values);
xlabel(‘Time’);
ylabel(‘PRx Value’);
title(‘PRx’);
grid on;
% Calculate average PRx
average_PRx = mean(PRx_values);
% Display average PRx
fprintf(‘Average PRx: %.4f\n’, average_PRx);
This is the script I am trying to calculate PRx with:
%PRx_calc
% Load ICP and MAP data
load("ICP,data_part1of1");
ICP_time_vector = round(time_vector); % Assuming time_vector in ICP file
ICP_data = measurement_data;
load("ABP,mean,data_part1of1");
ABP_time_vector = round(time_vector); % Assuming time_vector in ABP file
ABP_data = measurement_data;
% Remove duplicate time points from ICP
[ICP_time_vector, uniqueIdx] = unique(ICP_time_vector);
ICP_data = ICP_data(uniqueIdx);
% Remove duplicate time points from ABP
[ABP_time_vector, uniqueIdx] = unique(ABP_time_vector);
ABP_data = ABP_data(uniqueIdx);
% Ensure consistent dimensions
if length(ICP_time_vector) ~= length(ICP_data)
error(‘ICP_time_vector and ICP_data have different lengths’);
end
if length(ABP_time_vector) ~= length(ABP_data)
error(‘ABP_time_vector and ABP_data have different lengths’);
end
% Interpolating ABP to match ICP time vector
if ~isequal(ICP_time_vector, ABP_time_vector)
ABP_data = interp1(ABP_time_vector, ABP_data, ICP_time_vector, ‘linear’, ‘extrap’);
end
% Combine ICP data and aligned ABP data
ICP = [ICP_time_vector(:), ICP_data(:)]; % Ensure column vectors
ABP = [ICP_time_vector(:), ABP_data(:)]; % ABP_data is now interpolated to match ICP_time_vector
% Parameters
windowSize = 30 * 10; % 30 windows of 10 seconds
stepSize = 60; % Update every 60 seconds
n = length(ICP_time_vector); % Number of data points
% Preallocate PRx array
PRx = NaN(floor((n – windowSize) / stepSize) + 1, 1);
% Compute moving correlation coefficient
for i = 1:stepSize:(n – windowSize + 1)
% Extract current window of data
windowICP = ICP(i:i + windowSize – 1, 2);
windowABP = ABP(i:i + windowSize – 1, 2);
% Calculate correlation coefficient for the current window
R = corrcoef(windowICP, windowABP);
% Store PRx (correlation coefficient of ICP and ABP)
PRx(floor(i / stepSize) + 1) = R(1, 2);
end
% Calculate average PRx ignoring NaN values
averagePRx = sum(PRx, ‘omitnan’) / sum(~isnan(PRx));
% Display average PRx in the command window
fprintf(‘Average PRx: %.4f\n’, averagePRx);
% Plot PRx vs Time in minutes
figure;
plot((0:length(PRx)-1)*stepSize/60, PRx); % Convert to minutes
title(‘PRx vs Time’);
xlabel(‘Time (minutes)’);
ylabel(‘PRx Values’);
I thought the calculation script would work, but it doesn’t. For instance, for a certain set of data, PRx_calc.m gives me an average PRx value of 0.32, while PRx_display.m gives me 0.52. The trend of the plots look the same, but the PRx_calc.m’s for some reason looks shifted down and distorted a little bit. I am looking for help with the way I am using the corrcoef function and general debugging help.
Here are the first 20 values of each type of data: First 20 values of
ICP: 10 10 10 10 11 11 11 11 10 11 10 11 11 11 11 11 10 11 11 11
First 20 values of
ABP: 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89
First 20 calculated
PRx values: NaN NaN NaN NaN NaN NaN -0.0838 -0.2111 -0.0586 0.1704 0.4276 0.3193 0.3417 0.4128 0.5488 0.4790 0.5207 0.6822 0.7107 0.5235
Average PRx: 0.3209
The PRx_calc script, which produces the above values, should produce the given PRx values(below).
First 20 PRx Values: 0.6150 0.5996 0.6010 0.6276 0.7499 0.4495 0.4488 0.4492 0.5078 0.7263 0.7290 0.7343 0.7490 0.7561 0.6997 0.4609 0.2567 0.5935 0.7317 0.6666
Average PRx: 0.5247
Please let me know if there is anything else I should add, more data points, graphs, etc. Thank you! Hi everyone! I need to calculate PRx (pressure reactivity index) using ICP (intracranial pressure) and mean ABP (mean arterial blood pressure) data. PRx is known as "pressure reactivity index is calculated as the degree of statistical correlation between the slow wave components of mean arterial pressure (ABP) and intracranial pressure (ICP)". I need to do this in order to calculate a different hypothetical reactivity index. I have PRx data- so my idea was to use the given PRx data and compare it to the calculated PRx data to ensure it is correct.
This is the script to display the PRx data that was given to me:
%PRx_display
% Load PRx data from MAT file
load(‘PRx,data_part1of1’);
PRx_values = measurement_data;
disp(‘PRx Values:’);
disp(PRx_values);
% Plot PRx values
figure;
plot(PRx_values);
xlabel(‘Time’);
ylabel(‘PRx Value’);
title(‘PRx’);
grid on;
% Calculate average PRx
average_PRx = mean(PRx_values);
% Display average PRx
fprintf(‘Average PRx: %.4f\n’, average_PRx);
This is the script I am trying to calculate PRx with:
%PRx_calc
% Load ICP and MAP data
load("ICP,data_part1of1");
ICP_time_vector = round(time_vector); % Assuming time_vector in ICP file
ICP_data = measurement_data;
load("ABP,mean,data_part1of1");
ABP_time_vector = round(time_vector); % Assuming time_vector in ABP file
ABP_data = measurement_data;
% Remove duplicate time points from ICP
[ICP_time_vector, uniqueIdx] = unique(ICP_time_vector);
ICP_data = ICP_data(uniqueIdx);
% Remove duplicate time points from ABP
[ABP_time_vector, uniqueIdx] = unique(ABP_time_vector);
ABP_data = ABP_data(uniqueIdx);
% Ensure consistent dimensions
if length(ICP_time_vector) ~= length(ICP_data)
error(‘ICP_time_vector and ICP_data have different lengths’);
end
if length(ABP_time_vector) ~= length(ABP_data)
error(‘ABP_time_vector and ABP_data have different lengths’);
end
% Interpolating ABP to match ICP time vector
if ~isequal(ICP_time_vector, ABP_time_vector)
ABP_data = interp1(ABP_time_vector, ABP_data, ICP_time_vector, ‘linear’, ‘extrap’);
end
% Combine ICP data and aligned ABP data
ICP = [ICP_time_vector(:), ICP_data(:)]; % Ensure column vectors
ABP = [ICP_time_vector(:), ABP_data(:)]; % ABP_data is now interpolated to match ICP_time_vector
% Parameters
windowSize = 30 * 10; % 30 windows of 10 seconds
stepSize = 60; % Update every 60 seconds
n = length(ICP_time_vector); % Number of data points
% Preallocate PRx array
PRx = NaN(floor((n – windowSize) / stepSize) + 1, 1);
% Compute moving correlation coefficient
for i = 1:stepSize:(n – windowSize + 1)
% Extract current window of data
windowICP = ICP(i:i + windowSize – 1, 2);
windowABP = ABP(i:i + windowSize – 1, 2);
% Calculate correlation coefficient for the current window
R = corrcoef(windowICP, windowABP);
% Store PRx (correlation coefficient of ICP and ABP)
PRx(floor(i / stepSize) + 1) = R(1, 2);
end
% Calculate average PRx ignoring NaN values
averagePRx = sum(PRx, ‘omitnan’) / sum(~isnan(PRx));
% Display average PRx in the command window
fprintf(‘Average PRx: %.4f\n’, averagePRx);
% Plot PRx vs Time in minutes
figure;
plot((0:length(PRx)-1)*stepSize/60, PRx); % Convert to minutes
title(‘PRx vs Time’);
xlabel(‘Time (minutes)’);
ylabel(‘PRx Values’);
I thought the calculation script would work, but it doesn’t. For instance, for a certain set of data, PRx_calc.m gives me an average PRx value of 0.32, while PRx_display.m gives me 0.52. The trend of the plots look the same, but the PRx_calc.m’s for some reason looks shifted down and distorted a little bit. I am looking for help with the way I am using the corrcoef function and general debugging help.
Here are the first 20 values of each type of data: First 20 values of
ICP: 10 10 10 10 11 11 11 11 10 11 10 11 11 11 11 11 10 11 11 11
First 20 values of
ABP: 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89 89
First 20 calculated
PRx values: NaN NaN NaN NaN NaN NaN -0.0838 -0.2111 -0.0586 0.1704 0.4276 0.3193 0.3417 0.4128 0.5488 0.4790 0.5207 0.6822 0.7107 0.5235
Average PRx: 0.3209
The PRx_calc script, which produces the above values, should produce the given PRx values(below).
First 20 PRx Values: 0.6150 0.5996 0.6010 0.6276 0.7499 0.4495 0.4488 0.4492 0.5078 0.7263 0.7290 0.7343 0.7490 0.7561 0.6997 0.4609 0.2567 0.5935 0.7317 0.6666
Average PRx: 0.5247
Please let me know if there is anything else I should add, more data points, graphs, etc. Thank you! corrcoef MATLAB Answers — New Questions
Can I deploy a multiwindow app as a web app using MATLAB Web App Server?
This documentation page shows the workflow of creating a multiwindow app with the App Designer.
https://www.mathworks.com/help/matlab/creating_guis/creating-multiwindow-apps-in-app-designer.html
However, after successfully deploying and launching the app from the web app server, I get errors such as:
Web Apps does not support multiwindow apps
Or:
Error using errordlg (line 2)
Web Apps does not support errordlg.
Can I deploy a multiwindow app as a web app using MATLAB Web App Server?This documentation page shows the workflow of creating a multiwindow app with the App Designer.
https://www.mathworks.com/help/matlab/creating_guis/creating-multiwindow-apps-in-app-designer.html
However, after successfully deploying and launching the app from the web app server, I get errors such as:
Web Apps does not support multiwindow apps
Or:
Error using errordlg (line 2)
Web Apps does not support errordlg.
Can I deploy a multiwindow app as a web app using MATLAB Web App Server? This documentation page shows the workflow of creating a multiwindow app with the App Designer.
https://www.mathworks.com/help/matlab/creating_guis/creating-multiwindow-apps-in-app-designer.html
However, after successfully deploying and launching the app from the web app server, I get errors such as:
Web Apps does not support multiwindow apps
Or:
Error using errordlg (line 2)
Web Apps does not support errordlg.
Can I deploy a multiwindow app as a web app using MATLAB Web App Server? multiwindowapp, webapplimitations MATLAB Answers — New Questions
Get singular sagittal slice from nifti file saved as axial slices
Hello, with the following code i’m able to retrieve a single axial slice from this nifti file of a lung CT scan. I would like to know how to be able to save a slice from another view, such as sagittal or coronal in a separate image format such at png or jpg for image processing.
L1 = load_nii(‘lung_029.nii’);
NumSlices = size(L1.img,3)
S = L1.img(:,:,125);
figure
imshow(S)
I’m using the image processing toolbox and tools for nifti and analyze image add ons.Hello, with the following code i’m able to retrieve a single axial slice from this nifti file of a lung CT scan. I would like to know how to be able to save a slice from another view, such as sagittal or coronal in a separate image format such at png or jpg for image processing.
L1 = load_nii(‘lung_029.nii’);
NumSlices = size(L1.img,3)
S = L1.img(:,:,125);
figure
imshow(S)
I’m using the image processing toolbox and tools for nifti and analyze image add ons. Hello, with the following code i’m able to retrieve a single axial slice from this nifti file of a lung CT scan. I would like to know how to be able to save a slice from another view, such as sagittal or coronal in a separate image format such at png or jpg for image processing.
L1 = load_nii(‘lung_029.nii’);
NumSlices = size(L1.img,3)
S = L1.img(:,:,125);
figure
imshow(S)
I’m using the image processing toolbox and tools for nifti and analyze image add ons. nifti, image processing, medical images MATLAB Answers — New Questions
Code not displaying figure
I was told to implement this code form a texbok, but it isn’t displaying figure like in textbook. Last lines separated by enter has display figure part
I prefer to keep it together as one code. I am very new to matlab.
close all
%image parameters
W = 400;
H = 400;
% object parameters
rho = 200;
A = 0.4;
B = 0.2;
alpha = pi /10;
xo = 0.3;
yo = 0.5;
% backprojection parameters
ntheta = 100;
srange = 2;
ns = 100;
function [P] = ellipseproj(A, B, rho, theta, s, alpha, xo, yo)
gamma = atan2(yo, xo);
d = sqrt( xo * xo + yo * yo);
thetanew = theta – alpha;
snew = s – d * cos(gamma – theta);
% use translated/rotated values
s = snew;
theta = thetanew;
% find a^2 (theta)
ct = cos(theta);
st = sin(theta);
a2 = A*A*ct*ct + B*B*st*st;
atheta = sqrt(a2);
% return value if outside ellipse
P = 0;
if( abs(s) <= atheta )
% inside ellipse
P = 2 * rho * A * B / a2 * sqrt(a2 – s * s);
end
end %added
function [projmat, svals, thetavals] = …
ellipseprojmat(A, B, ntheta, ns, srange, rho, alpha, xo, yo)
thetamin = 0;
thetamax = pi;
% each row is a projection at a certain angle
projmat = zeros(ntheta, ns);
smin = -srange;
smax = srange;
dtheta = pi/(ntheta – 1);
ds = (smax – smin)/(ns – 1);
svals = smin:ds:smax;
thetavals = thetamin:dtheta:thetamax;
pn = 1;
for theta = thetavals
% calculate all points on the projection line
P = zeros(ns, 1);
ip = 1;
for s = svals
% simple ellipse
[p] = ellipseproj(A, B, rho, theta, s, alpha, xo, yo);
P(ip) = p;
ip = ip + 1;
end
% save projection as one row of matrix
projmat(pn, 🙂 = P’;
pn = pn + 1;
end
end %added
function [b] = bpsolve(W, H, projmat, svals, thetavals)
ntheta = length(thetavals);
ns = length(svals);
srange = svals(ns);
b = zeros(H, W);
for iy = 1:H
for ix = 1:W
x = 2 * (ix – 1)/(W – 1) – 1;
y = 1 – 2 * (iy – 1)/(H – 1);
% projmat is the P values, each row is P(s) for a given theta
bsum = 0;
for itheta = 1:ntheta
theta = thetavals(itheta);
s =x*cos(theta) + y*sin(theta);
is = (s + srange)/(srange*2)*(ns – 1) + 1;
is = round(is);
if(is < 1)
is = 1;
end
if(is > ns)
is = ns;
end
Ptheta = projmat(itheta, is);
bsum = bsum + Ptheta;
end
b(iy, ix) = bsum;
end
end
% image parameters
W = 400;
H = 400;
% object parameters
% rho = 200;
A = 0.4;
B = 0.2;
alpha = pi/10;
xo = 0.3;
yo = 0.5;
% backprojection parameters
ntheta = 100;
srange = 2;
ns = 100;
% generate projections
[projmat, svals, thetavals] = …
ellipseprojmat(A, B, ntheta, ns, srange, rho, alpha, xo, yo); % solve using backprojection
[b] = bpsolve(W, H, projmat, svals, thetavals);
% scale for image display
b = b/max(max(b)); b = b*255;
bi = uint8(b);
figure(1);
clf
image(bi);
colormap(gray(256));
box(‘on’);
axis(‘off’);
shg;
saveas(gcf,’CompileData.png’);
end %addedI was told to implement this code form a texbok, but it isn’t displaying figure like in textbook. Last lines separated by enter has display figure part
I prefer to keep it together as one code. I am very new to matlab.
close all
%image parameters
W = 400;
H = 400;
% object parameters
rho = 200;
A = 0.4;
B = 0.2;
alpha = pi /10;
xo = 0.3;
yo = 0.5;
% backprojection parameters
ntheta = 100;
srange = 2;
ns = 100;
function [P] = ellipseproj(A, B, rho, theta, s, alpha, xo, yo)
gamma = atan2(yo, xo);
d = sqrt( xo * xo + yo * yo);
thetanew = theta – alpha;
snew = s – d * cos(gamma – theta);
% use translated/rotated values
s = snew;
theta = thetanew;
% find a^2 (theta)
ct = cos(theta);
st = sin(theta);
a2 = A*A*ct*ct + B*B*st*st;
atheta = sqrt(a2);
% return value if outside ellipse
P = 0;
if( abs(s) <= atheta )
% inside ellipse
P = 2 * rho * A * B / a2 * sqrt(a2 – s * s);
end
end %added
function [projmat, svals, thetavals] = …
ellipseprojmat(A, B, ntheta, ns, srange, rho, alpha, xo, yo)
thetamin = 0;
thetamax = pi;
% each row is a projection at a certain angle
projmat = zeros(ntheta, ns);
smin = -srange;
smax = srange;
dtheta = pi/(ntheta – 1);
ds = (smax – smin)/(ns – 1);
svals = smin:ds:smax;
thetavals = thetamin:dtheta:thetamax;
pn = 1;
for theta = thetavals
% calculate all points on the projection line
P = zeros(ns, 1);
ip = 1;
for s = svals
% simple ellipse
[p] = ellipseproj(A, B, rho, theta, s, alpha, xo, yo);
P(ip) = p;
ip = ip + 1;
end
% save projection as one row of matrix
projmat(pn, 🙂 = P’;
pn = pn + 1;
end
end %added
function [b] = bpsolve(W, H, projmat, svals, thetavals)
ntheta = length(thetavals);
ns = length(svals);
srange = svals(ns);
b = zeros(H, W);
for iy = 1:H
for ix = 1:W
x = 2 * (ix – 1)/(W – 1) – 1;
y = 1 – 2 * (iy – 1)/(H – 1);
% projmat is the P values, each row is P(s) for a given theta
bsum = 0;
for itheta = 1:ntheta
theta = thetavals(itheta);
s =x*cos(theta) + y*sin(theta);
is = (s + srange)/(srange*2)*(ns – 1) + 1;
is = round(is);
if(is < 1)
is = 1;
end
if(is > ns)
is = ns;
end
Ptheta = projmat(itheta, is);
bsum = bsum + Ptheta;
end
b(iy, ix) = bsum;
end
end
% image parameters
W = 400;
H = 400;
% object parameters
% rho = 200;
A = 0.4;
B = 0.2;
alpha = pi/10;
xo = 0.3;
yo = 0.5;
% backprojection parameters
ntheta = 100;
srange = 2;
ns = 100;
% generate projections
[projmat, svals, thetavals] = …
ellipseprojmat(A, B, ntheta, ns, srange, rho, alpha, xo, yo); % solve using backprojection
[b] = bpsolve(W, H, projmat, svals, thetavals);
% scale for image display
b = b/max(max(b)); b = b*255;
bi = uint8(b);
figure(1);
clf
image(bi);
colormap(gray(256));
box(‘on’);
axis(‘off’);
shg;
saveas(gcf,’CompileData.png’);
end %added I was told to implement this code form a texbok, but it isn’t displaying figure like in textbook. Last lines separated by enter has display figure part
I prefer to keep it together as one code. I am very new to matlab.
close all
%image parameters
W = 400;
H = 400;
% object parameters
rho = 200;
A = 0.4;
B = 0.2;
alpha = pi /10;
xo = 0.3;
yo = 0.5;
% backprojection parameters
ntheta = 100;
srange = 2;
ns = 100;
function [P] = ellipseproj(A, B, rho, theta, s, alpha, xo, yo)
gamma = atan2(yo, xo);
d = sqrt( xo * xo + yo * yo);
thetanew = theta – alpha;
snew = s – d * cos(gamma – theta);
% use translated/rotated values
s = snew;
theta = thetanew;
% find a^2 (theta)
ct = cos(theta);
st = sin(theta);
a2 = A*A*ct*ct + B*B*st*st;
atheta = sqrt(a2);
% return value if outside ellipse
P = 0;
if( abs(s) <= atheta )
% inside ellipse
P = 2 * rho * A * B / a2 * sqrt(a2 – s * s);
end
end %added
function [projmat, svals, thetavals] = …
ellipseprojmat(A, B, ntheta, ns, srange, rho, alpha, xo, yo)
thetamin = 0;
thetamax = pi;
% each row is a projection at a certain angle
projmat = zeros(ntheta, ns);
smin = -srange;
smax = srange;
dtheta = pi/(ntheta – 1);
ds = (smax – smin)/(ns – 1);
svals = smin:ds:smax;
thetavals = thetamin:dtheta:thetamax;
pn = 1;
for theta = thetavals
% calculate all points on the projection line
P = zeros(ns, 1);
ip = 1;
for s = svals
% simple ellipse
[p] = ellipseproj(A, B, rho, theta, s, alpha, xo, yo);
P(ip) = p;
ip = ip + 1;
end
% save projection as one row of matrix
projmat(pn, 🙂 = P’;
pn = pn + 1;
end
end %added
function [b] = bpsolve(W, H, projmat, svals, thetavals)
ntheta = length(thetavals);
ns = length(svals);
srange = svals(ns);
b = zeros(H, W);
for iy = 1:H
for ix = 1:W
x = 2 * (ix – 1)/(W – 1) – 1;
y = 1 – 2 * (iy – 1)/(H – 1);
% projmat is the P values, each row is P(s) for a given theta
bsum = 0;
for itheta = 1:ntheta
theta = thetavals(itheta);
s =x*cos(theta) + y*sin(theta);
is = (s + srange)/(srange*2)*(ns – 1) + 1;
is = round(is);
if(is < 1)
is = 1;
end
if(is > ns)
is = ns;
end
Ptheta = projmat(itheta, is);
bsum = bsum + Ptheta;
end
b(iy, ix) = bsum;
end
end
% image parameters
W = 400;
H = 400;
% object parameters
% rho = 200;
A = 0.4;
B = 0.2;
alpha = pi/10;
xo = 0.3;
yo = 0.5;
% backprojection parameters
ntheta = 100;
srange = 2;
ns = 100;
% generate projections
[projmat, svals, thetavals] = …
ellipseprojmat(A, B, ntheta, ns, srange, rho, alpha, xo, yo); % solve using backprojection
[b] = bpsolve(W, H, projmat, svals, thetavals);
% scale for image display
b = b/max(max(b)); b = b*255;
bi = uint8(b);
figure(1);
clf
image(bi);
colormap(gray(256));
box(‘on’);
axis(‘off’);
shg;
saveas(gcf,’CompileData.png’);
end %added figure MATLAB Answers — New Questions
Extract the information of inside and outside of a contourf
Hello everyone,
I have a single line of code, quite simple, thanks to which I get (visually) exactly what I need:
h=figure; [pippo1, pippo2]=contourf(AZ,EL,FF, [0, 0]);
where the input arguments have size 301×301. The plot I get is like this:
As you can see, the outside of the contour is not only the big cyan area, but also some small areas in the white (not filled) polygon. I need the coordinates of the outside polygon (the whole cyan region) but I couldn’t extract them from either "h" or "pippo2". Please note, I DON’T NEED the coordinates of the single contours, because if I extract XDATA and YDATA they lose the information about "the inside" and the "outside". I need to extract, in some way, a single contour that represents the whole cyan area, and another one that represents the complementary (white) one.
Thanks a lot!Hello everyone,
I have a single line of code, quite simple, thanks to which I get (visually) exactly what I need:
h=figure; [pippo1, pippo2]=contourf(AZ,EL,FF, [0, 0]);
where the input arguments have size 301×301. The plot I get is like this:
As you can see, the outside of the contour is not only the big cyan area, but also some small areas in the white (not filled) polygon. I need the coordinates of the outside polygon (the whole cyan region) but I couldn’t extract them from either "h" or "pippo2". Please note, I DON’T NEED the coordinates of the single contours, because if I extract XDATA and YDATA they lose the information about "the inside" and the "outside". I need to extract, in some way, a single contour that represents the whole cyan area, and another one that represents the complementary (white) one.
Thanks a lot! Hello everyone,
I have a single line of code, quite simple, thanks to which I get (visually) exactly what I need:
h=figure; [pippo1, pippo2]=contourf(AZ,EL,FF, [0, 0]);
where the input arguments have size 301×301. The plot I get is like this:
As you can see, the outside of the contour is not only the big cyan area, but also some small areas in the white (not filled) polygon. I need the coordinates of the outside polygon (the whole cyan region) but I couldn’t extract them from either "h" or "pippo2". Please note, I DON’T NEED the coordinates of the single contours, because if I extract XDATA and YDATA they lose the information about "the inside" and the "outside". I need to extract, in some way, a single contour that represents the whole cyan area, and another one that represents the complementary (white) one.
Thanks a lot! outside and inside of contourf MATLAB Answers — New Questions
Code Generation from script file
I need information about tool box where I can generate code for SOC Estimations using MATLAB ODE solvers in (.m) Script file.I need information about tool box where I can generate code for SOC Estimations using MATLAB ODE solvers in (.m) Script file. I need information about tool box where I can generate code for SOC Estimations using MATLAB ODE solvers in (.m) Script file. bms MATLAB Answers — New Questions
用cec2022测试函数的mexw64文件运行时报出如下错误“Error: Cannot open M_1_D2.txt for reading Error: Cannot open shift_data_1.txt for reading Error: Cannot open M_2_D2.txt for reading ”
SearchAgents_no = 30;
Max_iter = 100;
for j = 1:12
[lb,ub,dim,fobj] = Get_Functions_cec2022(j,2);
[Best_Pos_PSA,Best_Score_PSA,Convergence_curve_PSA] = PSA(SearchAgents_no,Max_iter,lb,ub,dim,fobj);
endSearchAgents_no = 30;
Max_iter = 100;
for j = 1:12
[lb,ub,dim,fobj] = Get_Functions_cec2022(j,2);
[Best_Pos_PSA,Best_Score_PSA,Convergence_curve_PSA] = PSA(SearchAgents_no,Max_iter,lb,ub,dim,fobj);
end SearchAgents_no = 30;
Max_iter = 100;
for j = 1:12
[lb,ub,dim,fobj] = Get_Functions_cec2022(j,2);
[Best_Pos_PSA,Best_Score_PSA,Convergence_curve_PSA] = PSA(SearchAgents_no,Max_iter,lb,ub,dim,fobj);
end cec2022 MATLAB Answers — New Questions
How to restore example to default
I opened a Simulink example file and made modifications before thinking of making a working copy. Now I can’t get back to the original. How can I download it again from Mathworks?I opened a Simulink example file and made modifications before thinking of making a working copy. Now I can’t get back to the original. How can I download it again from Mathworks? I opened a Simulink example file and made modifications before thinking of making a working copy. Now I can’t get back to the original. How can I download it again from Mathworks? examples MATLAB Answers — New Questions
can you add probability to a for loop?
I have a very long and complex fitness function that I want to add even more complexity to, and I’m wondering if I can shortcut it.
The basic idea is that an individual has to choose between two patches to forage in and the patches can now have a varying probability, either high or low, of finding food.
I want the combination of probabilities to be different from each other, that is
p1 = prob of finding food in patch 1 = hi or lo
p2 = prob of finding food in patch 2 = hi or lo
(p1,p2) combinations
30% chance of (hi,lo)
25% chance of (hi,hi)
25% chance of (lo,lo)
20% chance of (lo,hi)
The most straight forward way would just be adding it up
total fitness Fd = 0.3(F1) + 0.25(F2) + 0.25(F3) + 0.2(F4)
My code for fitness is already very long with only one combination of finding food probabilities. Is there a way I could do a for loop with these combinations and add in that probability or do I have to go the long way around?I have a very long and complex fitness function that I want to add even more complexity to, and I’m wondering if I can shortcut it.
The basic idea is that an individual has to choose between two patches to forage in and the patches can now have a varying probability, either high or low, of finding food.
I want the combination of probabilities to be different from each other, that is
p1 = prob of finding food in patch 1 = hi or lo
p2 = prob of finding food in patch 2 = hi or lo
(p1,p2) combinations
30% chance of (hi,lo)
25% chance of (hi,hi)
25% chance of (lo,lo)
20% chance of (lo,hi)
The most straight forward way would just be adding it up
total fitness Fd = 0.3(F1) + 0.25(F2) + 0.25(F3) + 0.2(F4)
My code for fitness is already very long with only one combination of finding food probabilities. Is there a way I could do a for loop with these combinations and add in that probability or do I have to go the long way around? I have a very long and complex fitness function that I want to add even more complexity to, and I’m wondering if I can shortcut it.
The basic idea is that an individual has to choose between two patches to forage in and the patches can now have a varying probability, either high or low, of finding food.
I want the combination of probabilities to be different from each other, that is
p1 = prob of finding food in patch 1 = hi or lo
p2 = prob of finding food in patch 2 = hi or lo
(p1,p2) combinations
30% chance of (hi,lo)
25% chance of (hi,hi)
25% chance of (lo,lo)
20% chance of (lo,hi)
The most straight forward way would just be adding it up
total fitness Fd = 0.3(F1) + 0.25(F2) + 0.25(F3) + 0.2(F4)
My code for fitness is already very long with only one combination of finding food probabilities. Is there a way I could do a for loop with these combinations and add in that probability or do I have to go the long way around? for loop, probabilities MATLAB Answers — New Questions
How can I package the MATLAB Runtime Installer with my standalone application from a specific directory?
I am using the Application Compiler to build standalone desktop applications from my MATLAB code with MATLAB Compiler. I am using the "Runtime included in package" option to package the MATLAB Runtime with my application installer.
I am using "compiler.runtime.download" to download the ZIP-file for the MATLAB Runtime installer. However, the file is downloaded to a temporary directory. For example, the MATLAB Runtime for R2024a on Windows is downloaded to:
C:Users<username>AppDataLocalTemp<username>MCRInstaller24.1MATLAB_Runtime_R2024a_Update_4_win64.zip
After a few days, the temporary directory is cleared by my operating system, and I need to redownload it in order to package the Runtime with my application installer. How can I configure MATLAB to store the Runtime installer in a non-temporary directory to package with my standalone applications?I am using the Application Compiler to build standalone desktop applications from my MATLAB code with MATLAB Compiler. I am using the "Runtime included in package" option to package the MATLAB Runtime with my application installer.
I am using "compiler.runtime.download" to download the ZIP-file for the MATLAB Runtime installer. However, the file is downloaded to a temporary directory. For example, the MATLAB Runtime for R2024a on Windows is downloaded to:
C:Users<username>AppDataLocalTemp<username>MCRInstaller24.1MATLAB_Runtime_R2024a_Update_4_win64.zip
After a few days, the temporary directory is cleared by my operating system, and I need to redownload it in order to package the Runtime with my application installer. How can I configure MATLAB to store the Runtime installer in a non-temporary directory to package with my standalone applications? I am using the Application Compiler to build standalone desktop applications from my MATLAB code with MATLAB Compiler. I am using the "Runtime included in package" option to package the MATLAB Runtime with my application installer.
I am using "compiler.runtime.download" to download the ZIP-file for the MATLAB Runtime installer. However, the file is downloaded to a temporary directory. For example, the MATLAB Runtime for R2024a on Windows is downloaded to:
C:Users<username>AppDataLocalTemp<username>MCRInstaller24.1MATLAB_Runtime_R2024a_Update_4_win64.zip
After a few days, the temporary directory is cleared by my operating system, and I need to redownload it in order to package the Runtime with my application installer. How can I configure MATLAB to store the Runtime installer in a non-temporary directory to package with my standalone applications? applicationcompiler, matlabruntimeinstaller MATLAB Answers — New Questions
Contourf: fill inside instead of outside
Hi, how can I fill the area within the circle? At the moment Matlab fills the area outside. I would like the outside to be white and the inside to be filled. Thanks.
relamdt=-4:0.1:4;
imlamdt=-4:0.1:4;
[x,y]=meshgrid(relamdt,imlamdt);
axis square;
lamdt=x+i*y;
sig = (1 + lamdt);
v = [1,1];
contourf(x,y,abs(sig),v)Hi, how can I fill the area within the circle? At the moment Matlab fills the area outside. I would like the outside to be white and the inside to be filled. Thanks.
relamdt=-4:0.1:4;
imlamdt=-4:0.1:4;
[x,y]=meshgrid(relamdt,imlamdt);
axis square;
lamdt=x+i*y;
sig = (1 + lamdt);
v = [1,1];
contourf(x,y,abs(sig),v) Hi, how can I fill the area within the circle? At the moment Matlab fills the area outside. I would like the outside to be white and the inside to be filled. Thanks.
relamdt=-4:0.1:4;
imlamdt=-4:0.1:4;
[x,y]=meshgrid(relamdt,imlamdt);
axis square;
lamdt=x+i*y;
sig = (1 + lamdt);
v = [1,1];
contourf(x,y,abs(sig),v) contour, fill MATLAB Answers — New Questions
Simulink outputs variables but they are not being sent to the workspace.
While using my PC at home I am using ‘to workspace’ blocks in my diagram with save format array. When I run the simulation i get the following the the command window:
ans =
Simulink.SimulationOutput:
Vin: [2002×1 double]
Vout: [2002×1 double]
t: [2002×1 double]
tout: [2002×1 double]
SimulationMetadata: [1×1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char]
Undefined function or variable ‘t’.
Error in P1_2 (line 79)
plot(t,Vin,t,Vout)
It seems to me that simulink is outputting the variables but they are not appearing in the workspace and therefore it thinks they are undefined. I tried running the simulation on a computer at my university and it worked. I tried reinstalling Matlab on my home PC and it still doesnt work. Version 2019.While using my PC at home I am using ‘to workspace’ blocks in my diagram with save format array. When I run the simulation i get the following the the command window:
ans =
Simulink.SimulationOutput:
Vin: [2002×1 double]
Vout: [2002×1 double]
t: [2002×1 double]
tout: [2002×1 double]
SimulationMetadata: [1×1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char]
Undefined function or variable ‘t’.
Error in P1_2 (line 79)
plot(t,Vin,t,Vout)
It seems to me that simulink is outputting the variables but they are not appearing in the workspace and therefore it thinks they are undefined. I tried running the simulation on a computer at my university and it worked. I tried reinstalling Matlab on my home PC and it still doesnt work. Version 2019. While using my PC at home I am using ‘to workspace’ blocks in my diagram with save format array. When I run the simulation i get the following the the command window:
ans =
Simulink.SimulationOutput:
Vin: [2002×1 double]
Vout: [2002×1 double]
t: [2002×1 double]
tout: [2002×1 double]
SimulationMetadata: [1×1 Simulink.SimulationMetadata]
ErrorMessage: [0x0 char]
Undefined function or variable ‘t’.
Error in P1_2 (line 79)
plot(t,Vin,t,Vout)
It seems to me that simulink is outputting the variables but they are not appearing in the workspace and therefore it thinks they are undefined. I tried running the simulation on a computer at my university and it worked. I tried reinstalling Matlab on my home PC and it still doesnt work. Version 2019. workspace, simulink MATLAB Answers — New Questions
how to write a code on matlab for a function that runs until she gets a regional answer
hi everyone!
i have a code i need to write-
i need to write a function that gets from the user amount of money he has and ask him how much money he wants to bet on.
the function needs to check that the value is regional and make sense and afterwards, if the value is good it will stop running, is isnt it will keep running until the user will insert regional value.
so far i wrote this- and its working but i dont know how to make the function keep running till the value is good
could use your help it will be helpful
thanx
function betamount = bet(money)
betamount= input(‘on what amount do you want to bet on?: ‘);
if ~isnumeric(betamount)|| betamount<=0 || betamount>money
disp(‘the betamount is invaild, try again’);
end
endhi everyone!
i have a code i need to write-
i need to write a function that gets from the user amount of money he has and ask him how much money he wants to bet on.
the function needs to check that the value is regional and make sense and afterwards, if the value is good it will stop running, is isnt it will keep running until the user will insert regional value.
so far i wrote this- and its working but i dont know how to make the function keep running till the value is good
could use your help it will be helpful
thanx
function betamount = bet(money)
betamount= input(‘on what amount do you want to bet on?: ‘);
if ~isnumeric(betamount)|| betamount<=0 || betamount>money
disp(‘the betamount is invaild, try again’);
end
end hi everyone!
i have a code i need to write-
i need to write a function that gets from the user amount of money he has and ask him how much money he wants to bet on.
the function needs to check that the value is regional and make sense and afterwards, if the value is good it will stop running, is isnt it will keep running until the user will insert regional value.
so far i wrote this- and its working but i dont know how to make the function keep running till the value is good
could use your help it will be helpful
thanx
function betamount = bet(money)
betamount= input(‘on what amount do you want to bet on?: ‘);
if ~isnumeric(betamount)|| betamount<=0 || betamount>money
disp(‘the betamount is invaild, try again’);
end
end function, functions, loop, if statement, while loop MATLAB Answers — New Questions
2 synchronized objects in viewer3d
(Running Matlab 2023b)
Dear Community,
how can I have two volshow objects side by side in viewer3d that follow the same rotation/zoom commands via mouse?
Or how can I have two viewer3d that have linked mouse commands?
In essence I am looking for a functionality like "linkaxes" only for viewer3d
Where to look?
Many thanks,
André(Running Matlab 2023b)
Dear Community,
how can I have two volshow objects side by side in viewer3d that follow the same rotation/zoom commands via mouse?
Or how can I have two viewer3d that have linked mouse commands?
In essence I am looking for a functionality like "linkaxes" only for viewer3d
Where to look?
Many thanks,
André (Running Matlab 2023b)
Dear Community,
how can I have two volshow objects side by side in viewer3d that follow the same rotation/zoom commands via mouse?
Or how can I have two viewer3d that have linked mouse commands?
In essence I am looking for a functionality like "linkaxes" only for viewer3d
Where to look?
Many thanks,
André viewer3d, linkaxes, volshow MATLAB Answers — New Questions
How to increase resolution from gshhs?
Dear all,
The code below allowed me to download and plot the coastline of UK. However, I would like to have a better resolution. When i change, in line 13 of the code below, ‘gshhs_c.b.gz’ for ‘gshhs_h.b.gz’ an error appeared (see below). So, How can I have the best coastal resolution of the area I an interested in? please can soemone help me?
Error using checkfilename>validateFilename (line 157)
Function GUNZIP was unable to find file ”gshhs_h.b.gz”.
Error in checkfilename (line 49)
[fullfilename, fid] = validateFilename( …
Error in gunzip>checkFilesURLInput (line 124)
[fullFileName, url] = checkfilename(inputFiles{1}, validExtensions, fcnName, …
Error in gunzip (line 63)
[files, url, urlFilename] = checkFilesURLInput(files, {‘gz’},’FILES’,mfilename);
Error in test (line 13)
files = gunzip(‘gshhs_h.b.gz’, workingFolder);
close all
clear all
clc
% assign the path to your working directory:
cd (‘E:SEEC’);
% add path to TelemacTolls functions (i.e. to read in telemac files into MATLAB):
addpath (‘C:Matlab_downloadm_map1.4f’);
workingFolder = tempdir;
files = gunzip(‘gshhs_c.b.gz’, workingFolder);
filename = files{1};
indexfile = gshhs(filename, ‘createindex’);
latlim = [50.45 56.31];
lonlim = [-8.1 -2.1];
S = gshhs(filename, latlim, lonlim);
delete(filename)
delete(indexfile)
levels = [S.Level];
L1 = S(levels == 1);
figure
axesm(‘mercator’, ‘MapLatLimit’, latlim, ‘MapLonLimit’, lonlim)
gridm; mlabel; plabel
geoshow([L1.Lat], [L1.Lon], ‘Color’, ‘blue’)Dear all,
The code below allowed me to download and plot the coastline of UK. However, I would like to have a better resolution. When i change, in line 13 of the code below, ‘gshhs_c.b.gz’ for ‘gshhs_h.b.gz’ an error appeared (see below). So, How can I have the best coastal resolution of the area I an interested in? please can soemone help me?
Error using checkfilename>validateFilename (line 157)
Function GUNZIP was unable to find file ”gshhs_h.b.gz”.
Error in checkfilename (line 49)
[fullfilename, fid] = validateFilename( …
Error in gunzip>checkFilesURLInput (line 124)
[fullFileName, url] = checkfilename(inputFiles{1}, validExtensions, fcnName, …
Error in gunzip (line 63)
[files, url, urlFilename] = checkFilesURLInput(files, {‘gz’},’FILES’,mfilename);
Error in test (line 13)
files = gunzip(‘gshhs_h.b.gz’, workingFolder);
close all
clear all
clc
% assign the path to your working directory:
cd (‘E:SEEC’);
% add path to TelemacTolls functions (i.e. to read in telemac files into MATLAB):
addpath (‘C:Matlab_downloadm_map1.4f’);
workingFolder = tempdir;
files = gunzip(‘gshhs_c.b.gz’, workingFolder);
filename = files{1};
indexfile = gshhs(filename, ‘createindex’);
latlim = [50.45 56.31];
lonlim = [-8.1 -2.1];
S = gshhs(filename, latlim, lonlim);
delete(filename)
delete(indexfile)
levels = [S.Level];
L1 = S(levels == 1);
figure
axesm(‘mercator’, ‘MapLatLimit’, latlim, ‘MapLonLimit’, lonlim)
gridm; mlabel; plabel
geoshow([L1.Lat], [L1.Lon], ‘Color’, ‘blue’) Dear all,
The code below allowed me to download and plot the coastline of UK. However, I would like to have a better resolution. When i change, in line 13 of the code below, ‘gshhs_c.b.gz’ for ‘gshhs_h.b.gz’ an error appeared (see below). So, How can I have the best coastal resolution of the area I an interested in? please can soemone help me?
Error using checkfilename>validateFilename (line 157)
Function GUNZIP was unable to find file ”gshhs_h.b.gz”.
Error in checkfilename (line 49)
[fullfilename, fid] = validateFilename( …
Error in gunzip>checkFilesURLInput (line 124)
[fullFileName, url] = checkfilename(inputFiles{1}, validExtensions, fcnName, …
Error in gunzip (line 63)
[files, url, urlFilename] = checkFilesURLInput(files, {‘gz’},’FILES’,mfilename);
Error in test (line 13)
files = gunzip(‘gshhs_h.b.gz’, workingFolder);
close all
clear all
clc
% assign the path to your working directory:
cd (‘E:SEEC’);
% add path to TelemacTolls functions (i.e. to read in telemac files into MATLAB):
addpath (‘C:Matlab_downloadm_map1.4f’);
workingFolder = tempdir;
files = gunzip(‘gshhs_c.b.gz’, workingFolder);
filename = files{1};
indexfile = gshhs(filename, ‘createindex’);
latlim = [50.45 56.31];
lonlim = [-8.1 -2.1];
S = gshhs(filename, latlim, lonlim);
delete(filename)
delete(indexfile)
levels = [S.Level];
L1 = S(levels == 1);
figure
axesm(‘mercator’, ‘MapLatLimit’, latlim, ‘MapLonLimit’, lonlim)
gridm; mlabel; plabel
geoshow([L1.Lat], [L1.Lon], ‘Color’, ‘blue’) gshhs, increase reoslution MATLAB Answers — New Questions
Simbiology Previous Initial Parameters
Hi! So I saved a run when I was doing fitting for my data, and put the results in a folder on the Simbiology model analzyer dashboard. I wanted to replicate that saved data but I can’t seem to find where the initial parameters for that run are stored? If anyone could help or if there’s any way I can further clarify please let me know!Hi! So I saved a run when I was doing fitting for my data, and put the results in a folder on the Simbiology model analzyer dashboard. I wanted to replicate that saved data but I can’t seem to find where the initial parameters for that run are stored? If anyone could help or if there’s any way I can further clarify please let me know! Hi! So I saved a run when I was doing fitting for my data, and put the results in a folder on the Simbiology model analzyer dashboard. I wanted to replicate that saved data but I can’t seem to find where the initial parameters for that run are stored? If anyone could help or if there’s any way I can further clarify please let me know! matlab, simbiology, initial parameters, curve fitting, simulation MATLAB Answers — New Questions
Why are functions called by “eval” not found by my compiled standalone application?
I have a function "databaseConnectWithEval" that is defined as follows:
function conn = databaseConnectWithEval
conn = eval(‘database("MySQL ODBC","username","password");’);
end
If I call this function from the MATLAB Command Window, it works as expected.
However, if I compile this function into a standalone application, and then run the executable, the following error is thrown:
Undefined function ‘database’ for input arguments of type ‘char’.
If I use the following function, without "eval", then both the function and the compiled executable work as expected.
function conn = databaseConnect
conn = database("MySQL ODBC","username","password");
end
Why is this function inside of "eval" not found by my compiled application?I have a function "databaseConnectWithEval" that is defined as follows:
function conn = databaseConnectWithEval
conn = eval(‘database("MySQL ODBC","username","password");’);
end
If I call this function from the MATLAB Command Window, it works as expected.
However, if I compile this function into a standalone application, and then run the executable, the following error is thrown:
Undefined function ‘database’ for input arguments of type ‘char’.
If I use the following function, without "eval", then both the function and the compiled executable work as expected.
function conn = databaseConnect
conn = database("MySQL ODBC","username","password");
end
Why is this function inside of "eval" not found by my compiled application? I have a function "databaseConnectWithEval" that is defined as follows:
function conn = databaseConnectWithEval
conn = eval(‘database("MySQL ODBC","username","password");’);
end
If I call this function from the MATLAB Command Window, it works as expected.
However, if I compile this function into a standalone application, and then run the executable, the following error is thrown:
Undefined function ‘database’ for input arguments of type ‘char’.
If I use the following function, without "eval", then both the function and the compiled executable work as expected.
function conn = databaseConnect
conn = database("MySQL ODBC","username","password");
end
Why is this function inside of "eval" not found by my compiled application? eval, compiler MATLAB Answers — New Questions
installing matlab and simulink on pi – ‘verifying sudo user privilege failed’
hi there,
i am trying to install matlab and simulink on my raspberry pi, but i keep getting the error ‘verifying sudo user privilege failed’
i have followed the steps in this article by matlab and enabled passwordless sudo but it still isn’t working.
Anybody encountered this problem before?
Thankshi there,
i am trying to install matlab and simulink on my raspberry pi, but i keep getting the error ‘verifying sudo user privilege failed’
i have followed the steps in this article by matlab and enabled passwordless sudo but it still isn’t working.
Anybody encountered this problem before?
Thanks hi there,
i am trying to install matlab and simulink on my raspberry pi, but i keep getting the error ‘verifying sudo user privilege failed’
i have followed the steps in this article by matlab and enabled passwordless sudo but it still isn’t working.
Anybody encountered this problem before?
Thanks raspberry pi, matlab, simulink, install MATLAB Answers — New Questions
Error message when trying to run System Validation in Fuzzy Logic Designer app
When I run the System Validation function I get the following error message in Workspace.
‘Tri 3×3’ is the name of the FIS I’ve designed.
All other simulation functions work fine.When I run the System Validation function I get the following error message in Workspace.
‘Tri 3×3’ is the name of the FIS I’ve designed.
All other simulation functions work fine. When I run the System Validation function I get the following error message in Workspace.
‘Tri 3×3’ is the name of the FIS I’ve designed.
All other simulation functions work fine. fuzzy logic designer app, system validation MATLAB Answers — New Questions
Reading a text file using readtable, Matlab stubbornly refuses to accept dates in anything but US-format
Here’s a programme I wrote to read in a data file. Rather than using the trusty, old-fashioned method I’ve always used (fopen, fgetl etc), I thought I’d use this fancy ‘readtable’ method. Half a day later, I wish I’d not bothered. The online help on this subject is very confusing, with changes in each version of Matlab from ‘Parameter’,’Value’ to ‘Parameter=Value’ to Parameter.value = … ways of doing things and so many parameters and sub-parameters in the readtable function that I got very confused. As you can see, I’ve tried 3 or 4 times to set the date format to read data from 10th March, but it still comes out as 3rd October.
Any help would be greatly appreciated.
%Script to read in data files
clear all
datetime.setDefaultFormats(‘default’,’dd/MM/yyyy’);
fid=fopen(‘Myfile’,’r’);
opts = detectImportOptions(‘Myfile’);
opts.VariableTypes(2)={‘datetime’};
opts.VariableOptions(1).DatetimeFormat=’dd/MM/yy’
opts.VariableOptions(1).InputFormat=’dd/MM/yy’
% setvaropts(opts,VariableOptions(1).InputFormat,’dd/MM/yyyy’);
A=readtable(‘Myfile’,’NumHeaderLines’,1);
A.Date.Format = ‘dd/MM/yyyy’
fclose(fid)
A{:,1}=datetime(A{:,1},’InputFormat’,’dd/MM/yyyy’, ‘Format’,’dd/MM/yyyy’)
d=datevec(A{:,1})+datevec(A{:,2});
d(:,1)=d(:,1)+2000;
t0=datenum(d);
Here’s the data-file I’m trying to read:
Patches found at BAKE00CAN between 10-Mar-2024 and 16-Mar-2024:
Date Time Latitude Longitude sTEC_inc Duratn./s
10/03/24 00:08:00 71.70 -88.73 3.2 1350
10/03/24 00:14:30 69.60 -110.59 4.9 840
10/03/24 00:16:00 62.46 -94.23 3.8 1620
10/03/24 00:18:00 64.35 -83.21 8.2 1470
10/03/24 00:23:30 72.70 -110.84 17.9 5370
10/03/24 00:25:30 63.86 -91.88 2.4 450
10/03/24 00:28:30 67.25 -85.28 4.1 1710
10/03/24 00:29:30 73.89 -90.16 2.7 570
10/03/24 00:31:00 62.88 -93.91 3.7 870
…but it comes out as:
A =
9×6 table
Date Time Latitude Longitude sTEC_inc Duratn__s
__________ ________ ________ _________ ________ _________
03/10/0024 00:08:00 71.7 -88.73 3.2 1350
03/10/0024 00:14:30 69.6 -110.59 4.9 840
03/10/0024 00:16:00 62.46 -94.23 3.8 1620
03/10/0024 00:18:00 64.35 -83.21 8.2 1470
03/10/0024 00:23:30 72.7 -110.84 17.9 5370
03/10/0024 00:25:30 63.86 -91.88 2.4 450
03/10/0024 00:28:30 67.25 -85.28 4.1 1710
03/10/0024 00:29:30 73.89 -90.16 2.7 570
03/10/0024 00:31:00 62.88 -93.91 3.7 870Here’s a programme I wrote to read in a data file. Rather than using the trusty, old-fashioned method I’ve always used (fopen, fgetl etc), I thought I’d use this fancy ‘readtable’ method. Half a day later, I wish I’d not bothered. The online help on this subject is very confusing, with changes in each version of Matlab from ‘Parameter’,’Value’ to ‘Parameter=Value’ to Parameter.value = … ways of doing things and so many parameters and sub-parameters in the readtable function that I got very confused. As you can see, I’ve tried 3 or 4 times to set the date format to read data from 10th March, but it still comes out as 3rd October.
Any help would be greatly appreciated.
%Script to read in data files
clear all
datetime.setDefaultFormats(‘default’,’dd/MM/yyyy’);
fid=fopen(‘Myfile’,’r’);
opts = detectImportOptions(‘Myfile’);
opts.VariableTypes(2)={‘datetime’};
opts.VariableOptions(1).DatetimeFormat=’dd/MM/yy’
opts.VariableOptions(1).InputFormat=’dd/MM/yy’
% setvaropts(opts,VariableOptions(1).InputFormat,’dd/MM/yyyy’);
A=readtable(‘Myfile’,’NumHeaderLines’,1);
A.Date.Format = ‘dd/MM/yyyy’
fclose(fid)
A{:,1}=datetime(A{:,1},’InputFormat’,’dd/MM/yyyy’, ‘Format’,’dd/MM/yyyy’)
d=datevec(A{:,1})+datevec(A{:,2});
d(:,1)=d(:,1)+2000;
t0=datenum(d);
Here’s the data-file I’m trying to read:
Patches found at BAKE00CAN between 10-Mar-2024 and 16-Mar-2024:
Date Time Latitude Longitude sTEC_inc Duratn./s
10/03/24 00:08:00 71.70 -88.73 3.2 1350
10/03/24 00:14:30 69.60 -110.59 4.9 840
10/03/24 00:16:00 62.46 -94.23 3.8 1620
10/03/24 00:18:00 64.35 -83.21 8.2 1470
10/03/24 00:23:30 72.70 -110.84 17.9 5370
10/03/24 00:25:30 63.86 -91.88 2.4 450
10/03/24 00:28:30 67.25 -85.28 4.1 1710
10/03/24 00:29:30 73.89 -90.16 2.7 570
10/03/24 00:31:00 62.88 -93.91 3.7 870
…but it comes out as:
A =
9×6 table
Date Time Latitude Longitude sTEC_inc Duratn__s
__________ ________ ________ _________ ________ _________
03/10/0024 00:08:00 71.7 -88.73 3.2 1350
03/10/0024 00:14:30 69.6 -110.59 4.9 840
03/10/0024 00:16:00 62.46 -94.23 3.8 1620
03/10/0024 00:18:00 64.35 -83.21 8.2 1470
03/10/0024 00:23:30 72.7 -110.84 17.9 5370
03/10/0024 00:25:30 63.86 -91.88 2.4 450
03/10/0024 00:28:30 67.25 -85.28 4.1 1710
03/10/0024 00:29:30 73.89 -90.16 2.7 570
03/10/0024 00:31:00 62.88 -93.91 3.7 870 Here’s a programme I wrote to read in a data file. Rather than using the trusty, old-fashioned method I’ve always used (fopen, fgetl etc), I thought I’d use this fancy ‘readtable’ method. Half a day later, I wish I’d not bothered. The online help on this subject is very confusing, with changes in each version of Matlab from ‘Parameter’,’Value’ to ‘Parameter=Value’ to Parameter.value = … ways of doing things and so many parameters and sub-parameters in the readtable function that I got very confused. As you can see, I’ve tried 3 or 4 times to set the date format to read data from 10th March, but it still comes out as 3rd October.
Any help would be greatly appreciated.
%Script to read in data files
clear all
datetime.setDefaultFormats(‘default’,’dd/MM/yyyy’);
fid=fopen(‘Myfile’,’r’);
opts = detectImportOptions(‘Myfile’);
opts.VariableTypes(2)={‘datetime’};
opts.VariableOptions(1).DatetimeFormat=’dd/MM/yy’
opts.VariableOptions(1).InputFormat=’dd/MM/yy’
% setvaropts(opts,VariableOptions(1).InputFormat,’dd/MM/yyyy’);
A=readtable(‘Myfile’,’NumHeaderLines’,1);
A.Date.Format = ‘dd/MM/yyyy’
fclose(fid)
A{:,1}=datetime(A{:,1},’InputFormat’,’dd/MM/yyyy’, ‘Format’,’dd/MM/yyyy’)
d=datevec(A{:,1})+datevec(A{:,2});
d(:,1)=d(:,1)+2000;
t0=datenum(d);
Here’s the data-file I’m trying to read:
Patches found at BAKE00CAN between 10-Mar-2024 and 16-Mar-2024:
Date Time Latitude Longitude sTEC_inc Duratn./s
10/03/24 00:08:00 71.70 -88.73 3.2 1350
10/03/24 00:14:30 69.60 -110.59 4.9 840
10/03/24 00:16:00 62.46 -94.23 3.8 1620
10/03/24 00:18:00 64.35 -83.21 8.2 1470
10/03/24 00:23:30 72.70 -110.84 17.9 5370
10/03/24 00:25:30 63.86 -91.88 2.4 450
10/03/24 00:28:30 67.25 -85.28 4.1 1710
10/03/24 00:29:30 73.89 -90.16 2.7 570
10/03/24 00:31:00 62.88 -93.91 3.7 870
…but it comes out as:
A =
9×6 table
Date Time Latitude Longitude sTEC_inc Duratn__s
__________ ________ ________ _________ ________ _________
03/10/0024 00:08:00 71.7 -88.73 3.2 1350
03/10/0024 00:14:30 69.6 -110.59 4.9 840
03/10/0024 00:16:00 62.46 -94.23 3.8 1620
03/10/0024 00:18:00 64.35 -83.21 8.2 1470
03/10/0024 00:23:30 72.7 -110.84 17.9 5370
03/10/0024 00:25:30 63.86 -91.88 2.4 450
03/10/0024 00:28:30 67.25 -85.28 4.1 1710
03/10/0024 00:29:30 73.89 -90.16 2.7 570
03/10/0024 00:31:00 62.88 -93.91 3.7 870 readtable, date format MATLAB Answers — New Questions