Category: Matlab
Category Archives: Matlab
Celsius to Fahrenheit or vice versa
Creating a program to convert Celsius to FahrenheitCreating a program to convert Celsius to Fahrenheit Creating a program to convert Celsius to Fahrenheit disp, celsius, fahrenheit, if, else MATLAB Answers — New Questions
Unable to resolve the name ‘half.typecast’
Hi guys,
I’m trying to understand the following line of code, where data is a 4D array of type uint16.
data_single = single(half.typecast(data));
I tried to digest the line by doing the following
B=half.typecast(data);
,but I’m getting the following error
Unable to resolve the name ‘half.typecast’.
My problem is not with the single part, but with half.typecast() part. Any feedback will be appreciated.Hi guys,
I’m trying to understand the following line of code, where data is a 4D array of type uint16.
data_single = single(half.typecast(data));
I tried to digest the line by doing the following
B=half.typecast(data);
,but I’m getting the following error
Unable to resolve the name ‘half.typecast’.
My problem is not with the single part, but with half.typecast() part. Any feedback will be appreciated. Hi guys,
I’m trying to understand the following line of code, where data is a 4D array of type uint16.
data_single = single(half.typecast(data));
I tried to digest the line by doing the following
B=half.typecast(data);
,but I’m getting the following error
Unable to resolve the name ‘half.typecast’.
My problem is not with the single part, but with half.typecast() part. Any feedback will be appreciated. half, typecast, single MATLAB Answers — New Questions
how to use audiowrite
clear; clc; close all;
data= load(‘am_data.mat’);
d=data.d’;
%
ds = d(16000+1:16000+2560);
%
Ds = fftshift(fft(ds));
%
f = ((-2560/2) : (2560/2 – 1)) * 0.100;
plot(f,abs(Ds));
%
T=1/256000;
t=(1:length(d))*T;
fc=-17000;
%
dm=d.*(exp(-1i*2*pi*t*fc))’;
%
Dm=fftshift(fft(dm(16000+1:16000+2560)));
%
figure();
plot(f,abs(Dm));
%
th = (-100:100)*T;
h = sin(10000*pi*th + 1e-6)./(10000*pi*th+1e-6);
%
figure()
plot(th,h);
%
dmf = conv(dm,h);
%
Dmf = fftshift(fft(dmf(16000+1:16000+2560)));
figure()
plot(f,abs(Dmf));
%
dmfs = dmf(1:32:end)/max(abs(dmf));
sound(real(dmfs));
pause;
%
sound(abs(dmfs));
%
audiowrite(‘test.wav’,dmfs,256000);clear; clc; close all;
data= load(‘am_data.mat’);
d=data.d’;
%
ds = d(16000+1:16000+2560);
%
Ds = fftshift(fft(ds));
%
f = ((-2560/2) : (2560/2 – 1)) * 0.100;
plot(f,abs(Ds));
%
T=1/256000;
t=(1:length(d))*T;
fc=-17000;
%
dm=d.*(exp(-1i*2*pi*t*fc))’;
%
Dm=fftshift(fft(dm(16000+1:16000+2560)));
%
figure();
plot(f,abs(Dm));
%
th = (-100:100)*T;
h = sin(10000*pi*th + 1e-6)./(10000*pi*th+1e-6);
%
figure()
plot(th,h);
%
dmf = conv(dm,h);
%
Dmf = fftshift(fft(dmf(16000+1:16000+2560)));
figure()
plot(f,abs(Dmf));
%
dmfs = dmf(1:32:end)/max(abs(dmf));
sound(real(dmfs));
pause;
%
sound(abs(dmfs));
%
audiowrite(‘test.wav’,dmfs,256000); clear; clc; close all;
data= load(‘am_data.mat’);
d=data.d’;
%
ds = d(16000+1:16000+2560);
%
Ds = fftshift(fft(ds));
%
f = ((-2560/2) : (2560/2 – 1)) * 0.100;
plot(f,abs(Ds));
%
T=1/256000;
t=(1:length(d))*T;
fc=-17000;
%
dm=d.*(exp(-1i*2*pi*t*fc))’;
%
Dm=fftshift(fft(dm(16000+1:16000+2560)));
%
figure();
plot(f,abs(Dm));
%
th = (-100:100)*T;
h = sin(10000*pi*th + 1e-6)./(10000*pi*th+1e-6);
%
figure()
plot(th,h);
%
dmf = conv(dm,h);
%
Dmf = fftshift(fft(dmf(16000+1:16000+2560)));
figure()
plot(f,abs(Dmf));
%
dmfs = dmf(1:32:end)/max(abs(dmf));
sound(real(dmfs));
pause;
%
sound(abs(dmfs));
%
audiowrite(‘test.wav’,dmfs,256000); audiowrite, wavfile MATLAB Answers — New Questions
“Access is denied.” Error
I am running a script where I’m trying to create a directory if the directory doesn’t already exist. The relevant section of my script
if exist(input_all_daily{1}.all_plots_location,’dir’) == 0
mkdir(input_all_daily{1}.all_plots_location)
else
end
Sometimes, when I run this script, I get an "Access is denied." error that references the mkdir line. When I rerun the script without making any changes, the "Access is denied." is no longer generated. I have no idea what do to about this error. Can someone please help?I am running a script where I’m trying to create a directory if the directory doesn’t already exist. The relevant section of my script
if exist(input_all_daily{1}.all_plots_location,’dir’) == 0
mkdir(input_all_daily{1}.all_plots_location)
else
end
Sometimes, when I run this script, I get an "Access is denied." error that references the mkdir line. When I rerun the script without making any changes, the "Access is denied." is no longer generated. I have no idea what do to about this error. Can someone please help? I am running a script where I’m trying to create a directory if the directory doesn’t already exist. The relevant section of my script
if exist(input_all_daily{1}.all_plots_location,’dir’) == 0
mkdir(input_all_daily{1}.all_plots_location)
else
end
Sometimes, when I run this script, I get an "Access is denied." error that references the mkdir line. When I rerun the script without making any changes, the "Access is denied." is no longer generated. I have no idea what do to about this error. Can someone please help? create, access, denied, directory MATLAB Answers — New Questions
How could I model a gas purging the liquid in tanks and pipes? How the interface between Gas and TL could be implemented to achieve purging?
I want to model a process that requires purging to displace the liquid in tanks and pipes. My model would be using a G-TL tank and pipes that fill the tank, a pump to recirculate the liquid, or pump out the content. The tank is also pressurized with gas that is additionally used to purge the system.I want to model a process that requires purging to displace the liquid in tanks and pipes. My model would be using a G-TL tank and pipes that fill the tank, a pump to recirculate the liquid, or pump out the content. The tank is also pressurized with gas that is additionally used to purge the system. I want to model a process that requires purging to displace the liquid in tanks and pipes. My model would be using a G-TL tank and pipes that fill the tank, a pump to recirculate the liquid, or pump out the content. The tank is also pressurized with gas that is additionally used to purge the system. gas, purge, tl-g MATLAB Answers — New Questions
Errors when I’m entering a section in System Composer Onramp
In the section "Connect to Simulink > Simulate and Test (System level Simulation)", the Tasks do not load properly. There are several errors in the console, several of the blocks are red, the Submit button is gray, and the Assessment pane is empty.
I am stuck at 76% completion.
How can I avoid this error and progress through the course?
This is what I see in the command prompt:
Warning: Error executing PreClose callback "Studio7_SLOnramp" for block diagram "SystemComposerOnramp": Output argument "position" (and possibly others) not assigned a value in the execution with "learning.simulink.getTrainingStudioPosition" function.
Error using evalin Unrecognized function or variable ‘quadcopterActivitySetup’.Error in learning.simulink.StudioMgr/runInitializationCode Error in learning.simulink.StudioMgr Error in learning.simulink.Application/setupStudioManager Error in learning.simulink.Application/setupSimulinkStudio Error in LearningApplication.setupSimulinkStudio Index exceeds the number of array elements. Index must not exceed 2.Error in learning.simulink.StudioMgr/setupTask Error in learning.simulink.Application/setupTask Error in LearningApplication.setupTaskIn the section "Connect to Simulink > Simulate and Test (System level Simulation)", the Tasks do not load properly. There are several errors in the console, several of the blocks are red, the Submit button is gray, and the Assessment pane is empty.
I am stuck at 76% completion.
How can I avoid this error and progress through the course?
This is what I see in the command prompt:
Warning: Error executing PreClose callback "Studio7_SLOnramp" for block diagram "SystemComposerOnramp": Output argument "position" (and possibly others) not assigned a value in the execution with "learning.simulink.getTrainingStudioPosition" function.
Error using evalin Unrecognized function or variable ‘quadcopterActivitySetup’.Error in learning.simulink.StudioMgr/runInitializationCode Error in learning.simulink.StudioMgr Error in learning.simulink.Application/setupStudioManager Error in learning.simulink.Application/setupSimulinkStudio Error in LearningApplication.setupSimulinkStudio Index exceeds the number of array elements. Index must not exceed 2.Error in learning.simulink.StudioMgr/setupTask Error in learning.simulink.Application/setupTask Error in LearningApplication.setupTask In the section "Connect to Simulink > Simulate and Test (System level Simulation)", the Tasks do not load properly. There are several errors in the console, several of the blocks are red, the Submit button is gray, and the Assessment pane is empty.
I am stuck at 76% completion.
How can I avoid this error and progress through the course?
This is what I see in the command prompt:
Warning: Error executing PreClose callback "Studio7_SLOnramp" for block diagram "SystemComposerOnramp": Output argument "position" (and possibly others) not assigned a value in the execution with "learning.simulink.getTrainingStudioPosition" function.
Error using evalin Unrecognized function or variable ‘quadcopterActivitySetup’.Error in learning.simulink.StudioMgr/runInitializationCode Error in learning.simulink.StudioMgr Error in learning.simulink.Application/setupStudioManager Error in learning.simulink.Application/setupSimulinkStudio Error in LearningApplication.setupSimulinkStudio Index exceeds the number of array elements. Index must not exceed 2.Error in learning.simulink.StudioMgr/setupTask Error in learning.simulink.Application/setupTask Error in LearningApplication.setupTask onramp, system composer MATLAB Answers — New Questions
Appending data when extracting nested fields as individual variables
Hi Matlab community,
I have a variable "hands" that contains several fields, and I am trying to make hand_type, one of the fields, as an individual variable. The size of "hands" varies between 1×1 struct and 1×2 struct, hence I used the if-elseif loop. When "hands" is 1×2 struct, I want the second group of data to be stored in a parallel cell next to the first group of data, hence the {end+1}, as I don’t want them to be in the same cell and create an additional layer of nesting.
However, in the resulting "hand_type", whenever "hands" is 1×2 struct, "hand_type" only has 0x0 double. In comparison, when "hands" is 1×1 struct, "hand_type" has a value of a number (0, 1, etc).
Could someone help me to identify what I am doing wrong, and how I can fix the problem? The full script is attached.
Thank you in advance!
has_hands = ~cellfun(@isempty, {frames.hands});
filtered_frames = frames(has_hands);
id = {filtered_frames.id};
time = {filtered_frames.timestamp};
hands = {filtered_frames.hands};
hand_type = cell(size(hands));
for i = 1:numel(hands)
if isequal(size(hands{i}),[1,1])
hand_type{i} = hands{i}.type;
elseif isequal(size(hands{i}),[1,2])
hand_type{end+1} = hands{i}(1).type;
hand_type{end+1} = hands{i}(2).type;
endHi Matlab community,
I have a variable "hands" that contains several fields, and I am trying to make hand_type, one of the fields, as an individual variable. The size of "hands" varies between 1×1 struct and 1×2 struct, hence I used the if-elseif loop. When "hands" is 1×2 struct, I want the second group of data to be stored in a parallel cell next to the first group of data, hence the {end+1}, as I don’t want them to be in the same cell and create an additional layer of nesting.
However, in the resulting "hand_type", whenever "hands" is 1×2 struct, "hand_type" only has 0x0 double. In comparison, when "hands" is 1×1 struct, "hand_type" has a value of a number (0, 1, etc).
Could someone help me to identify what I am doing wrong, and how I can fix the problem? The full script is attached.
Thank you in advance!
has_hands = ~cellfun(@isempty, {frames.hands});
filtered_frames = frames(has_hands);
id = {filtered_frames.id};
time = {filtered_frames.timestamp};
hands = {filtered_frames.hands};
hand_type = cell(size(hands));
for i = 1:numel(hands)
if isequal(size(hands{i}),[1,1])
hand_type{i} = hands{i}.type;
elseif isequal(size(hands{i}),[1,2])
hand_type{end+1} = hands{i}(1).type;
hand_type{end+1} = hands{i}(2).type;
end Hi Matlab community,
I have a variable "hands" that contains several fields, and I am trying to make hand_type, one of the fields, as an individual variable. The size of "hands" varies between 1×1 struct and 1×2 struct, hence I used the if-elseif loop. When "hands" is 1×2 struct, I want the second group of data to be stored in a parallel cell next to the first group of data, hence the {end+1}, as I don’t want them to be in the same cell and create an additional layer of nesting.
However, in the resulting "hand_type", whenever "hands" is 1×2 struct, "hand_type" only has 0x0 double. In comparison, when "hands" is 1×1 struct, "hand_type" has a value of a number (0, 1, etc).
Could someone help me to identify what I am doing wrong, and how I can fix the problem? The full script is attached.
Thank you in advance!
has_hands = ~cellfun(@isempty, {frames.hands});
filtered_frames = frames(has_hands);
id = {filtered_frames.id};
time = {filtered_frames.timestamp};
hands = {filtered_frames.hands};
hand_type = cell(size(hands));
for i = 1:numel(hands)
if isequal(size(hands{i}),[1,1])
hand_type{i} = hands{i}.type;
elseif isequal(size(hands{i}),[1,2])
hand_type{end+1} = hands{i}(1).type;
hand_type{end+1} = hands{i}(2).type;
end append, nesting, variable, indexing, if statement, loop MATLAB Answers — New Questions
Error using trainNetwork Invalid training data. For cell array input, responses must be an N-by-1 cell array of sequences, where N is the number of sequences. The spatial and
Error using trainNetwork
Invalid training data. For cell array input, responses must be an N-by-1 cell array of sequences, where N is the number of sequences. The spatial and channel dimensions of the sequences must be the same as the output size of the last layer (1).
% Edit – running code here
load CycleAgeingData.mat
numHiddenUnits = 50;
inputSize1 = size(Data{1},1)
% layers = [
% sequenceInputLayer(numChannels)
% lstmLayer(128)
% fullyConnectedLayer(numChannels)
% regressionLayer];
%
layers = [ …
sequenceInputLayer(inputSize1)
lstmLayer(50, ‘OutputMode’, ‘sequence’)
fullyConnectedLayer(7)
dropoutLayer(0.011547480894612765)
fullyConnectedLayer(1)
regressionLayer];
% layersLSTM = [ …
% sequenceInputLayer(inputSize1)
% lstmLayer(numHiddenUnits)
% fullyConnectedLayer(1)
% regressionLayer
% ];
% cell1x = num2cell(features’, 1)’;
% targets=cap6/cap6(1)
% cell1yB = num2cell(targets);
numChannels = size(Data{1},1)
numObservations = numel(Data);
idxTrain = 1:floor(0.7*numObservations);
idxval = floor(0.7*numObservations)+1:numObservations-2
idxTest = floor(0.7*numObservations)+4:numObservations;
dataTrain = Data(idxTrain);
dataVal = Data(idxval)
dataTest = Data(idxTest);
trainindx=(1:24)
validindx=(25:29)
testindx=(30:34)
traincell2yB = target(idxTrain, :);
valcell2yB = target(idxval, :);
testcell2yB = target(idxTest, :);
options = trainingOptions(‘rmsprop’, …
‘MaxEpochs’, 1500, …
‘MiniBatchSize’, 50, …
‘InitialLearnRate’, 0.00036008553147273947, …
‘LearnRateSchedule’, ‘piecewise’, …
‘LearnRateDropPeriod’, 125, …
‘LearnRateDropFactor’, 0.02, …
‘Shuffle’, ‘every-epoch’, …
‘ValidationData’, {dataVal, valcell2yB}, …
‘ValidationFrequency’, 50, …
‘Verbose’, 1, …
‘Plots’, ‘training-progress’);
% options = trainingOptions(‘rmsprop’, …
% ‘InitialLearnRate’, 0.001, …
% ‘MaxEpochs’,500, …
% ‘MiniBatchSize’,50, …
% ‘Plots’,’training-progress’, ‘ValidationData’, {valcell1x, valcell1yB});
% options = trainingOptions(‘adam’, …
% ‘InitialLearnRate’, 0.001, …
% ‘MaxEpochs’,500, …
% ‘MiniBatchSize’,50, …
% ‘Plots’,’training-progress’, ‘ValidationData’, {valcell1x, valcell1yB});
netLSTM1 = trainNetwork(dataTrain, traincell2yB, layers, options);
Here is my dataError using trainNetwork
Invalid training data. For cell array input, responses must be an N-by-1 cell array of sequences, where N is the number of sequences. The spatial and channel dimensions of the sequences must be the same as the output size of the last layer (1).
% Edit – running code here
load CycleAgeingData.mat
numHiddenUnits = 50;
inputSize1 = size(Data{1},1)
% layers = [
% sequenceInputLayer(numChannels)
% lstmLayer(128)
% fullyConnectedLayer(numChannels)
% regressionLayer];
%
layers = [ …
sequenceInputLayer(inputSize1)
lstmLayer(50, ‘OutputMode’, ‘sequence’)
fullyConnectedLayer(7)
dropoutLayer(0.011547480894612765)
fullyConnectedLayer(1)
regressionLayer];
% layersLSTM = [ …
% sequenceInputLayer(inputSize1)
% lstmLayer(numHiddenUnits)
% fullyConnectedLayer(1)
% regressionLayer
% ];
% cell1x = num2cell(features’, 1)’;
% targets=cap6/cap6(1)
% cell1yB = num2cell(targets);
numChannels = size(Data{1},1)
numObservations = numel(Data);
idxTrain = 1:floor(0.7*numObservations);
idxval = floor(0.7*numObservations)+1:numObservations-2
idxTest = floor(0.7*numObservations)+4:numObservations;
dataTrain = Data(idxTrain);
dataVal = Data(idxval)
dataTest = Data(idxTest);
trainindx=(1:24)
validindx=(25:29)
testindx=(30:34)
traincell2yB = target(idxTrain, :);
valcell2yB = target(idxval, :);
testcell2yB = target(idxTest, :);
options = trainingOptions(‘rmsprop’, …
‘MaxEpochs’, 1500, …
‘MiniBatchSize’, 50, …
‘InitialLearnRate’, 0.00036008553147273947, …
‘LearnRateSchedule’, ‘piecewise’, …
‘LearnRateDropPeriod’, 125, …
‘LearnRateDropFactor’, 0.02, …
‘Shuffle’, ‘every-epoch’, …
‘ValidationData’, {dataVal, valcell2yB}, …
‘ValidationFrequency’, 50, …
‘Verbose’, 1, …
‘Plots’, ‘training-progress’);
% options = trainingOptions(‘rmsprop’, …
% ‘InitialLearnRate’, 0.001, …
% ‘MaxEpochs’,500, …
% ‘MiniBatchSize’,50, …
% ‘Plots’,’training-progress’, ‘ValidationData’, {valcell1x, valcell1yB});
% options = trainingOptions(‘adam’, …
% ‘InitialLearnRate’, 0.001, …
% ‘MaxEpochs’,500, …
% ‘MiniBatchSize’,50, …
% ‘Plots’,’training-progress’, ‘ValidationData’, {valcell1x, valcell1yB});
netLSTM1 = trainNetwork(dataTrain, traincell2yB, layers, options);
Here is my data Error using trainNetwork
Invalid training data. For cell array input, responses must be an N-by-1 cell array of sequences, where N is the number of sequences. The spatial and channel dimensions of the sequences must be the same as the output size of the last layer (1).
% Edit – running code here
load CycleAgeingData.mat
numHiddenUnits = 50;
inputSize1 = size(Data{1},1)
% layers = [
% sequenceInputLayer(numChannels)
% lstmLayer(128)
% fullyConnectedLayer(numChannels)
% regressionLayer];
%
layers = [ …
sequenceInputLayer(inputSize1)
lstmLayer(50, ‘OutputMode’, ‘sequence’)
fullyConnectedLayer(7)
dropoutLayer(0.011547480894612765)
fullyConnectedLayer(1)
regressionLayer];
% layersLSTM = [ …
% sequenceInputLayer(inputSize1)
% lstmLayer(numHiddenUnits)
% fullyConnectedLayer(1)
% regressionLayer
% ];
% cell1x = num2cell(features’, 1)’;
% targets=cap6/cap6(1)
% cell1yB = num2cell(targets);
numChannels = size(Data{1},1)
numObservations = numel(Data);
idxTrain = 1:floor(0.7*numObservations);
idxval = floor(0.7*numObservations)+1:numObservations-2
idxTest = floor(0.7*numObservations)+4:numObservations;
dataTrain = Data(idxTrain);
dataVal = Data(idxval)
dataTest = Data(idxTest);
trainindx=(1:24)
validindx=(25:29)
testindx=(30:34)
traincell2yB = target(idxTrain, :);
valcell2yB = target(idxval, :);
testcell2yB = target(idxTest, :);
options = trainingOptions(‘rmsprop’, …
‘MaxEpochs’, 1500, …
‘MiniBatchSize’, 50, …
‘InitialLearnRate’, 0.00036008553147273947, …
‘LearnRateSchedule’, ‘piecewise’, …
‘LearnRateDropPeriod’, 125, …
‘LearnRateDropFactor’, 0.02, …
‘Shuffle’, ‘every-epoch’, …
‘ValidationData’, {dataVal, valcell2yB}, …
‘ValidationFrequency’, 50, …
‘Verbose’, 1, …
‘Plots’, ‘training-progress’);
% options = trainingOptions(‘rmsprop’, …
% ‘InitialLearnRate’, 0.001, …
% ‘MaxEpochs’,500, …
% ‘MiniBatchSize’,50, …
% ‘Plots’,’training-progress’, ‘ValidationData’, {valcell1x, valcell1yB});
% options = trainingOptions(‘adam’, …
% ‘InitialLearnRate’, 0.001, …
% ‘MaxEpochs’,500, …
% ‘MiniBatchSize’,50, …
% ‘Plots’,’training-progress’, ‘ValidationData’, {valcell1x, valcell1yB});
netLSTM1 = trainNetwork(dataTrain, traincell2yB, layers, options);
Here is my data machine learning, neural network, data MATLAB Answers — New Questions
Plot 2D matrix on 2D graph
I have a matrix of 24 rows and 1000 columns. What I want is a 2D plot where, on the x-axis, I have the iterations and on the y-axis I have the value associated to each of the 24 row elements for the corresponding column (where column is indexed by iteration). So, that means, at each iteration I have 24 different colored plots. When I use plot(mygraph) I get a plot where I have the 24 row elements on the x-axis and on the y-axis I have the value for the row element changing vertically. However, I want to see the change in a row element over the course of the 1000 columns. I hope I made my question clear enough. Please help me in representing my data correctly, thank you!I have a matrix of 24 rows and 1000 columns. What I want is a 2D plot where, on the x-axis, I have the iterations and on the y-axis I have the value associated to each of the 24 row elements for the corresponding column (where column is indexed by iteration). So, that means, at each iteration I have 24 different colored plots. When I use plot(mygraph) I get a plot where I have the 24 row elements on the x-axis and on the y-axis I have the value for the row element changing vertically. However, I want to see the change in a row element over the course of the 1000 columns. I hope I made my question clear enough. Please help me in representing my data correctly, thank you! I have a matrix of 24 rows and 1000 columns. What I want is a 2D plot where, on the x-axis, I have the iterations and on the y-axis I have the value associated to each of the 24 row elements for the corresponding column (where column is indexed by iteration). So, that means, at each iteration I have 24 different colored plots. When I use plot(mygraph) I get a plot where I have the 24 row elements on the x-axis and on the y-axis I have the value for the row element changing vertically. However, I want to see the change in a row element over the course of the 1000 columns. I hope I made my question clear enough. Please help me in representing my data correctly, thank you! matlab, plot, graph, matrix MATLAB Answers — New Questions
Plotting Taylor series using python
Plot the Taylor series of exp(𝑥𝑥) for 𝑥𝑥 in [0,5], and overplot the exact curve as a dashed line for comparison. Write the program to allow for different numbers of terms, and have it set for 10 terms when you submit your program. You will need to include a function to calculate 𝑛𝑛! (written in Python, not a call to a numpy function). Compute the plots with ∆𝑥𝑥 = 0.1. You may use a numpy functions to initialise an array 𝑥𝑥𝑖𝑖, to initialise an array 𝑦𝑦𝑖𝑖 to store the Taylor series values, and an array 𝑦𝑦𝑦𝑦ℎ𝑖𝑖 to store the exact values of exp(𝑥𝑥).PPlot the Taylor series of exp(𝑥𝑥) for 𝑥𝑥 in [0,5], and overplot the exact curve as a dashed line for comparison. Write the program to allow for different numbers of terms, and have it set for 10 terms when you submit your program. You will need to include a function to calculate 𝑛𝑛! (written in Python, not a call to a numpy function). Compute the plots with ∆𝑥𝑥 = 0.1. You may use a numpy functions to initialise an array 𝑥𝑥𝑖𝑖, to initialise an array 𝑦𝑦𝑖𝑖 to store the Taylor series values, and an array 𝑦𝑦𝑦𝑦ℎ𝑖𝑖 to store the exact values of exp(𝑥𝑥).P Plot the Taylor series of exp(𝑥𝑥) for 𝑥𝑥 in [0,5], and overplot the exact curve as a dashed line for comparison. Write the program to allow for different numbers of terms, and have it set for 10 terms when you submit your program. You will need to include a function to calculate 𝑛𝑛! (written in Python, not a call to a numpy function). Compute the plots with ∆𝑥𝑥 = 0.1. You may use a numpy functions to initialise an array 𝑥𝑥𝑖𝑖, to initialise an array 𝑦𝑦𝑖𝑖 to store the Taylor series values, and an array 𝑦𝑦𝑦𝑦ℎ𝑖𝑖 to store the exact values of exp(𝑥𝑥).P import numpy MATLAB Answers — New Questions
Particle size distribution using image processing in MATLAB
http://jcp.bmj.com/content/62/6/481/F6.large.jpg
I want to plot the number of fat cells in the liver versus their size. For which I wanted to use the following steps.
Apply adaptive thresholding on the gray level image.
Find distance transform on the thresholded image.
Invert the distance transform and assign a high value to the background.
Extract marker using gray scale reconstruction and assign zero value to marker.
Apply watershed transformation on the marker embedded inverted distance image to obtain the segmented image.
Use gray scale reconstruction to find radius of each droplet and subsequently calculate area of each labelled droplet.
In step 3 how do I assign a high value to the background and can you help me with step 4?http://jcp.bmj.com/content/62/6/481/F6.large.jpg
I want to plot the number of fat cells in the liver versus their size. For which I wanted to use the following steps.
Apply adaptive thresholding on the gray level image.
Find distance transform on the thresholded image.
Invert the distance transform and assign a high value to the background.
Extract marker using gray scale reconstruction and assign zero value to marker.
Apply watershed transformation on the marker embedded inverted distance image to obtain the segmented image.
Use gray scale reconstruction to find radius of each droplet and subsequently calculate area of each labelled droplet.
In step 3 how do I assign a high value to the background and can you help me with step 4? http://jcp.bmj.com/content/62/6/481/F6.large.jpg
I want to plot the number of fat cells in the liver versus their size. For which I wanted to use the following steps.
Apply adaptive thresholding on the gray level image.
Find distance transform on the thresholded image.
Invert the distance transform and assign a high value to the background.
Extract marker using gray scale reconstruction and assign zero value to marker.
Apply watershed transformation on the marker embedded inverted distance image to obtain the segmented image.
Use gray scale reconstruction to find radius of each droplet and subsequently calculate area of each labelled droplet.
In step 3 how do I assign a high value to the background and can you help me with step 4? image processing MATLAB Answers — New Questions
How to use LQR for setpoint tracking?
Initially I was using LQR to regulate the error dynamics, i.e., I computed the gains for de = (A – BK)e, but this basically results in a PI controller since the control law (with integral action) is u = -K*e + ki*z. I have seen many sources teaching how to do it by augmenting the state vector with the integral of the error, expanding the matrices to A = [A 0; C 0], etc. but I still can’t understand how that works. I am working on a first order cruise control problem. From my observations the integral action is doing all the tracking and the -Kx term is only getting in the way, trying to regulate the state x to zero. Here is my code:
% Parameters
X_u = 0;
X_uu = 22.7841;
m = 5037.7;
% Equilibrium point x0
x0 = 20*1.852/3.6; % Longitudinal linear velocity in m/s
u0 = X_u*x0 + X_uu*x0^2 % Thrust in N
% Linearize system around x0
A = -(X_u/m + 2*X_uu/m*x0);
B = 1/m;
C = 1;
D = 0;
% System order
n = size(A,1);
% Open loop system
sys_ol = ss(A,B,C,D);
openloopPoles = eig(A)
% Augmented system with the integral of the error
A_hat = [A zeros(n,1);…
-C 0 ];
B_hat = [B; 0];
Br = [zeros(n,1); 1];
C_hat = [1 zeros(1,n)];
D_hat = 0;
% Q R matrices
Q = 1000*(C’*C);
R = 0.5e-3;
% Feedback gain
K_hat = lqr(A_hat, B_hat,Q,R)
K = K_hat(1)
ki = -K_hat(2)
% Scaling matrix
%Nbar = rscale(sys_ol,K)
% Closed loop system
AA = [A – B*K B*ki;-C 0];
BB = Br;
CC = [C 0];
DD = 0;
sys_cl = ss(AA, BB, CC, DD);
% Time vector
t = 0:0.1:30;
% Control input
u = u0*ones(size(t));
% Reference setpoint
r = 25*1.852/3.6*ones(size(t));
% Initial states
x0_hat = [x0,0]
% Simulate the response of the system
[y,t,x_hat] = lsim(sys_cl,r,t,x0_hat);
figure
plot(t, y*3.6/1.852, ‘k’, ‘LineWidth’, 1.5,’Color’,’k’)
xlabel(‘Time (seconds)’)
ylabel(‘Speed (knots)’)
title(‘Closed loop response with integrator’)
grid on
% Control effort (Thrust)
u_effort = -K*x_hat(:,1) + ki*x_hat(:,2);
figure
plot(t, u_effort,’Color’,’k’)
xlabel(‘Time (s)’)
ylabel(‘Thrust (N)’)
title(‘Control effort’)Initially I was using LQR to regulate the error dynamics, i.e., I computed the gains for de = (A – BK)e, but this basically results in a PI controller since the control law (with integral action) is u = -K*e + ki*z. I have seen many sources teaching how to do it by augmenting the state vector with the integral of the error, expanding the matrices to A = [A 0; C 0], etc. but I still can’t understand how that works. I am working on a first order cruise control problem. From my observations the integral action is doing all the tracking and the -Kx term is only getting in the way, trying to regulate the state x to zero. Here is my code:
% Parameters
X_u = 0;
X_uu = 22.7841;
m = 5037.7;
% Equilibrium point x0
x0 = 20*1.852/3.6; % Longitudinal linear velocity in m/s
u0 = X_u*x0 + X_uu*x0^2 % Thrust in N
% Linearize system around x0
A = -(X_u/m + 2*X_uu/m*x0);
B = 1/m;
C = 1;
D = 0;
% System order
n = size(A,1);
% Open loop system
sys_ol = ss(A,B,C,D);
openloopPoles = eig(A)
% Augmented system with the integral of the error
A_hat = [A zeros(n,1);…
-C 0 ];
B_hat = [B; 0];
Br = [zeros(n,1); 1];
C_hat = [1 zeros(1,n)];
D_hat = 0;
% Q R matrices
Q = 1000*(C’*C);
R = 0.5e-3;
% Feedback gain
K_hat = lqr(A_hat, B_hat,Q,R)
K = K_hat(1)
ki = -K_hat(2)
% Scaling matrix
%Nbar = rscale(sys_ol,K)
% Closed loop system
AA = [A – B*K B*ki;-C 0];
BB = Br;
CC = [C 0];
DD = 0;
sys_cl = ss(AA, BB, CC, DD);
% Time vector
t = 0:0.1:30;
% Control input
u = u0*ones(size(t));
% Reference setpoint
r = 25*1.852/3.6*ones(size(t));
% Initial states
x0_hat = [x0,0]
% Simulate the response of the system
[y,t,x_hat] = lsim(sys_cl,r,t,x0_hat);
figure
plot(t, y*3.6/1.852, ‘k’, ‘LineWidth’, 1.5,’Color’,’k’)
xlabel(‘Time (seconds)’)
ylabel(‘Speed (knots)’)
title(‘Closed loop response with integrator’)
grid on
% Control effort (Thrust)
u_effort = -K*x_hat(:,1) + ki*x_hat(:,2);
figure
plot(t, u_effort,’Color’,’k’)
xlabel(‘Time (s)’)
ylabel(‘Thrust (N)’)
title(‘Control effort’) Initially I was using LQR to regulate the error dynamics, i.e., I computed the gains for de = (A – BK)e, but this basically results in a PI controller since the control law (with integral action) is u = -K*e + ki*z. I have seen many sources teaching how to do it by augmenting the state vector with the integral of the error, expanding the matrices to A = [A 0; C 0], etc. but I still can’t understand how that works. I am working on a first order cruise control problem. From my observations the integral action is doing all the tracking and the -Kx term is only getting in the way, trying to regulate the state x to zero. Here is my code:
% Parameters
X_u = 0;
X_uu = 22.7841;
m = 5037.7;
% Equilibrium point x0
x0 = 20*1.852/3.6; % Longitudinal linear velocity in m/s
u0 = X_u*x0 + X_uu*x0^2 % Thrust in N
% Linearize system around x0
A = -(X_u/m + 2*X_uu/m*x0);
B = 1/m;
C = 1;
D = 0;
% System order
n = size(A,1);
% Open loop system
sys_ol = ss(A,B,C,D);
openloopPoles = eig(A)
% Augmented system with the integral of the error
A_hat = [A zeros(n,1);…
-C 0 ];
B_hat = [B; 0];
Br = [zeros(n,1); 1];
C_hat = [1 zeros(1,n)];
D_hat = 0;
% Q R matrices
Q = 1000*(C’*C);
R = 0.5e-3;
% Feedback gain
K_hat = lqr(A_hat, B_hat,Q,R)
K = K_hat(1)
ki = -K_hat(2)
% Scaling matrix
%Nbar = rscale(sys_ol,K)
% Closed loop system
AA = [A – B*K B*ki;-C 0];
BB = Br;
CC = [C 0];
DD = 0;
sys_cl = ss(AA, BB, CC, DD);
% Time vector
t = 0:0.1:30;
% Control input
u = u0*ones(size(t));
% Reference setpoint
r = 25*1.852/3.6*ones(size(t));
% Initial states
x0_hat = [x0,0]
% Simulate the response of the system
[y,t,x_hat] = lsim(sys_cl,r,t,x0_hat);
figure
plot(t, y*3.6/1.852, ‘k’, ‘LineWidth’, 1.5,’Color’,’k’)
xlabel(‘Time (seconds)’)
ylabel(‘Speed (knots)’)
title(‘Closed loop response with integrator’)
grid on
% Control effort (Thrust)
u_effort = -K*x_hat(:,1) + ki*x_hat(:,2);
figure
plot(t, u_effort,’Color’,’k’)
xlabel(‘Time (s)’)
ylabel(‘Thrust (N)’)
title(‘Control effort’) lqi, lqr, setpoint tracking MATLAB Answers — New Questions
Speed Up String Conversion
Hi all. I am trying to speed up string conversion of a table field as below :-
GoingUC=string(table2cell(Inps(:,5)));
Inps is a table with approximately 730000 records with 13 fields. I’ve got 6 categorical fields to convert and it is taking over 2.5 hours so I wondered if there was a quicker way to do this. I need a string array for the following code which converts the categorical strings to numbers in a map (which is quick) :-
[Unique_GoingU,~,GoingU_Numeric_Cats] = unique(GoingUC);
CTNM_GoingU=containers.Map(Unique_GoingU,num2cell(1:length(Unique_GoingU)));
NTD_GoingU=cell2mat(values(CTNM_GoingU,num2cell(GoingUC)));
It all works perfectly for my use but it’s just if I can speed it up that would be great.
Steve GrayHi all. I am trying to speed up string conversion of a table field as below :-
GoingUC=string(table2cell(Inps(:,5)));
Inps is a table with approximately 730000 records with 13 fields. I’ve got 6 categorical fields to convert and it is taking over 2.5 hours so I wondered if there was a quicker way to do this. I need a string array for the following code which converts the categorical strings to numbers in a map (which is quick) :-
[Unique_GoingU,~,GoingU_Numeric_Cats] = unique(GoingUC);
CTNM_GoingU=containers.Map(Unique_GoingU,num2cell(1:length(Unique_GoingU)));
NTD_GoingU=cell2mat(values(CTNM_GoingU,num2cell(GoingUC)));
It all works perfectly for my use but it’s just if I can speed it up that would be great.
Steve Gray Hi all. I am trying to speed up string conversion of a table field as below :-
GoingUC=string(table2cell(Inps(:,5)));
Inps is a table with approximately 730000 records with 13 fields. I’ve got 6 categorical fields to convert and it is taking over 2.5 hours so I wondered if there was a quicker way to do this. I need a string array for the following code which converts the categorical strings to numbers in a map (which is quick) :-
[Unique_GoingU,~,GoingU_Numeric_Cats] = unique(GoingUC);
CTNM_GoingU=containers.Map(Unique_GoingU,num2cell(1:length(Unique_GoingU)));
NTD_GoingU=cell2mat(values(CTNM_GoingU,num2cell(GoingUC)));
It all works perfectly for my use but it’s just if I can speed it up that would be great.
Steve Gray matlab, string, convert, speed MATLAB Answers — New Questions
How can I access the value of a string variable? I need to construct a file path from a string variable, but keep getting the variable name and not the string.
I want to construct a file path, "f" that I will use many times in a Matlab m file. From advice in an answer to someone else’s question, I am using the "fullfile" function. However, I am having what seems like a silly problem. Please see the example below.
I want to put "directory1" in the file path to get:
/Users/me/ch4/directory1/directory2/results/file_1.dat
However, when I do:
directory_name = "directory1";
f = fullfile(‘/Users/me/ch4’, directory_name, ‘directory2/results/file_1.dat’)
I get:
Error using matlab.io.ImportOptions/readtable (line 503)
Unable to find or open ‘/Users/me/ch4/directory_name/directory2/results/file_1.dat’. Check the path and filename or file permissions
How can I substitute the contents of the variable and not the variable name in the file path? Thank you for any advice.I want to construct a file path, "f" that I will use many times in a Matlab m file. From advice in an answer to someone else’s question, I am using the "fullfile" function. However, I am having what seems like a silly problem. Please see the example below.
I want to put "directory1" in the file path to get:
/Users/me/ch4/directory1/directory2/results/file_1.dat
However, when I do:
directory_name = "directory1";
f = fullfile(‘/Users/me/ch4’, directory_name, ‘directory2/results/file_1.dat’)
I get:
Error using matlab.io.ImportOptions/readtable (line 503)
Unable to find or open ‘/Users/me/ch4/directory_name/directory2/results/file_1.dat’. Check the path and filename or file permissions
How can I substitute the contents of the variable and not the variable name in the file path? Thank you for any advice. I want to construct a file path, "f" that I will use many times in a Matlab m file. From advice in an answer to someone else’s question, I am using the "fullfile" function. However, I am having what seems like a silly problem. Please see the example below.
I want to put "directory1" in the file path to get:
/Users/me/ch4/directory1/directory2/results/file_1.dat
However, when I do:
directory_name = "directory1";
f = fullfile(‘/Users/me/ch4’, directory_name, ‘directory2/results/file_1.dat’)
I get:
Error using matlab.io.ImportOptions/readtable (line 503)
Unable to find or open ‘/Users/me/ch4/directory_name/directory2/results/file_1.dat’. Check the path and filename or file permissions
How can I substitute the contents of the variable and not the variable name in the file path? Thank you for any advice. string, strings, variable, variables MATLAB Answers — New Questions
The error :undefined function getSampleTime for input arguments of type double
Matlab système bloc ‘ ‘ error occured when invoking getSampleTime methodMatlab système bloc ‘ ‘ error occured when invoking getSampleTime method Matlab système bloc ‘ ‘ error occured when invoking getSampleTime method getsampletime MATLAB Answers — New Questions
Solving a Nonlinear Equation using Newton-Raphson Method
It’s required to solve that equation:
f(x) = x.^3 – 0.165*x.^2 + 3.993*10.^-4
using Newton-Raphson Method with initial guess (x0 = 0.05) to 3 iterations and also, plot that function.
Please help me with the code (i have MATLAB R2010a) …
I want the code to be with steps and iterations and if possible calculate the error also, pleaseIt’s required to solve that equation:
f(x) = x.^3 – 0.165*x.^2 + 3.993*10.^-4
using Newton-Raphson Method with initial guess (x0 = 0.05) to 3 iterations and also, plot that function.
Please help me with the code (i have MATLAB R2010a) …
I want the code to be with steps and iterations and if possible calculate the error also, please It’s required to solve that equation:
f(x) = x.^3 – 0.165*x.^2 + 3.993*10.^-4
using Newton-Raphson Method with initial guess (x0 = 0.05) to 3 iterations and also, plot that function.
Please help me with the code (i have MATLAB R2010a) …
I want the code to be with steps and iterations and if possible calculate the error also, please newton-raphson MATLAB Answers — New Questions
Relation between flux linkage and voltage constant | power_PMSynchronousMachineParams
Hello to everyone,
I am currently working on mathematical modeling of permanent magnet synchronous motor and stuck in computing some variables from standart manufacturer specifications.
Actually, I want to understand how can I compute flux linkage from Back EMF (Ke) constant.
In Simulink, the Permanent Magnet Synchronous Machine block (Simulink Library -> Simscape/Power Systems/Specialized Technology/Fundamental Blocks/Machines), under the Advanced tab, there is a GUI which name is "Compute from standard manufacturer specifications". In this GUI, I am able to understand the math beyond the Voltage constant (ke) transformations between Vpeak/kRPM and Vrms/(rad/s). But I can’t understand how the "flux linkage established by magnets (V*s)" is calculating from this voltage constant value.
Unfortunately, there is no information in Help section of this block about this topic.
Can someone please explain this relation by mathematical derivations.
Thanks in advance.
Best Regards,
YasinHello to everyone,
I am currently working on mathematical modeling of permanent magnet synchronous motor and stuck in computing some variables from standart manufacturer specifications.
Actually, I want to understand how can I compute flux linkage from Back EMF (Ke) constant.
In Simulink, the Permanent Magnet Synchronous Machine block (Simulink Library -> Simscape/Power Systems/Specialized Technology/Fundamental Blocks/Machines), under the Advanced tab, there is a GUI which name is "Compute from standard manufacturer specifications". In this GUI, I am able to understand the math beyond the Voltage constant (ke) transformations between Vpeak/kRPM and Vrms/(rad/s). But I can’t understand how the "flux linkage established by magnets (V*s)" is calculating from this voltage constant value.
Unfortunately, there is no information in Help section of this block about this topic.
Can someone please explain this relation by mathematical derivations.
Thanks in advance.
Best Regards,
Yasin Hello to everyone,
I am currently working on mathematical modeling of permanent magnet synchronous motor and stuck in computing some variables from standart manufacturer specifications.
Actually, I want to understand how can I compute flux linkage from Back EMF (Ke) constant.
In Simulink, the Permanent Magnet Synchronous Machine block (Simulink Library -> Simscape/Power Systems/Specialized Technology/Fundamental Blocks/Machines), under the Advanced tab, there is a GUI which name is "Compute from standard manufacturer specifications". In this GUI, I am able to understand the math beyond the Voltage constant (ke) transformations between Vpeak/kRPM and Vrms/(rad/s). But I can’t understand how the "flux linkage established by magnets (V*s)" is calculating from this voltage constant value.
Unfortunately, there is no information in Help section of this block about this topic.
Can someone please explain this relation by mathematical derivations.
Thanks in advance.
Best Regards,
Yasin voltage constant, flux linkage, bemf constant, pmsm MATLAB Answers — New Questions
Attempting to account for lens distortion using ” undistortedImage = undistortImage(originalIMage, cameraParams)
I am using the MATLAB Camera Calibtion App. and am attempting to mitgate lens distortion via post processing.
% Auto-generated by cameraCalibrator app on 01-May-2024
%——————————————————-
% Define images to process
imageFileNames = {‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001 deg 2024-04-30 17-35-57.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 00015 deg w 5 deg tilt 2024-04-30 17-37-59.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000115 deg w 5 deg tilt 2024-04-30 17-38-56.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000123 deg w 5 deg tilt 2024-04-30 17-40-03.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000130 deg w 5 deg tilt 2024-04-30 17-41-40.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000138 deg w 5 deg tilt 2024-04-30 17-42-51.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 6 deg w neg 15 deg tilt 2024-04-30 17-48-28.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 13 deg w neg 15 deg tilt 2024-04-30 17-50-12.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 20 deg w neg 15 deg tilt 2024-04-30 17-51-04.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 27 deg w neg 15 deg tilt 2024-04-30 17-51-46.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 33 deg w neg 15 deg tilt 2024-04-30 17-52-37.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 39 deg w neg 15 deg tilt 2024-04-30 17-53-44.png’,…
};
% Detect checkerboards in images
[imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(imageFileNames);
imageFileNames = imageFileNames(imagesUsed);
% Read the first image to obtain image size
originalImage = imread(imageFileNames{1});
[mrows, ncols, ~] = size(originalImage);
% Generate world coordinates of the corners of the squares
squareSize = 1.270000e+01; % in units of ‘millimeters’
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
% Calibrate the camera
[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, …
‘EstimateSkew’, true, ‘EstimateTangentialDistortion’, true, …
‘NumRadialDistortionCoefficients’, 3, ‘WorldUnits’, ‘millimeters’, …
‘InitialIntrinsicMatrix’, [], ‘InitialRadialDistortion’, [], …
‘ImageSize’, [mrows, ncols]);
% View reprojection errors
h1=figure; showReprojectionErrors(cameraParams);
% Visualize pattern locations
h2=figure; showExtrinsics(cameraParams, ‘CameraCentric’);
% Display parameter estimation errors
displayErrors(estimationErrors, cameraParams);
% For example, you can use the calibration data to remove effects of lens distortion.
undistortedImage = undistortImage(originalImage, cameraParams);
% See additional examples of how to use the calibration data. At the prompt type:
% showdemo(‘MeasuringPlanarObjectsExample’)
% showdemo(‘StructureFromMotionExample’)
JUst not sure how to get from is Highlghted code above to an answer. Is it just a subtraction of cameraParams – original image that wil tell us how to adjust for distotion in post processed maner please??I am using the MATLAB Camera Calibtion App. and am attempting to mitgate lens distortion via post processing.
% Auto-generated by cameraCalibrator app on 01-May-2024
%——————————————————-
% Define images to process
imageFileNames = {‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001 deg 2024-04-30 17-35-57.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 00015 deg w 5 deg tilt 2024-04-30 17-37-59.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000115 deg w 5 deg tilt 2024-04-30 17-38-56.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000123 deg w 5 deg tilt 2024-04-30 17-40-03.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000130 deg w 5 deg tilt 2024-04-30 17-41-40.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000138 deg w 5 deg tilt 2024-04-30 17-42-51.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 6 deg w neg 15 deg tilt 2024-04-30 17-48-28.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 13 deg w neg 15 deg tilt 2024-04-30 17-50-12.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 20 deg w neg 15 deg tilt 2024-04-30 17-51-04.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 27 deg w neg 15 deg tilt 2024-04-30 17-51-46.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 33 deg w neg 15 deg tilt 2024-04-30 17-52-37.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 39 deg w neg 15 deg tilt 2024-04-30 17-53-44.png’,…
};
% Detect checkerboards in images
[imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(imageFileNames);
imageFileNames = imageFileNames(imagesUsed);
% Read the first image to obtain image size
originalImage = imread(imageFileNames{1});
[mrows, ncols, ~] = size(originalImage);
% Generate world coordinates of the corners of the squares
squareSize = 1.270000e+01; % in units of ‘millimeters’
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
% Calibrate the camera
[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, …
‘EstimateSkew’, true, ‘EstimateTangentialDistortion’, true, …
‘NumRadialDistortionCoefficients’, 3, ‘WorldUnits’, ‘millimeters’, …
‘InitialIntrinsicMatrix’, [], ‘InitialRadialDistortion’, [], …
‘ImageSize’, [mrows, ncols]);
% View reprojection errors
h1=figure; showReprojectionErrors(cameraParams);
% Visualize pattern locations
h2=figure; showExtrinsics(cameraParams, ‘CameraCentric’);
% Display parameter estimation errors
displayErrors(estimationErrors, cameraParams);
% For example, you can use the calibration data to remove effects of lens distortion.
undistortedImage = undistortImage(originalImage, cameraParams);
% See additional examples of how to use the calibration data. At the prompt type:
% showdemo(‘MeasuringPlanarObjectsExample’)
% showdemo(‘StructureFromMotionExample’)
JUst not sure how to get from is Highlghted code above to an answer. Is it just a subtraction of cameraParams – original image that wil tell us how to adjust for distotion in post processed maner please?? I am using the MATLAB Camera Calibtion App. and am attempting to mitgate lens distortion via post processing.
% Auto-generated by cameraCalibrator app on 01-May-2024
%——————————————————-
% Define images to process
imageFileNames = {‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001 deg 2024-04-30 17-35-57.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 00015 deg w 5 deg tilt 2024-04-30 17-37-59.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000115 deg w 5 deg tilt 2024-04-30 17-38-56.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000123 deg w 5 deg tilt 2024-04-30 17-40-03.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000130 deg w 5 deg tilt 2024-04-30 17-41-40.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 000138 deg w 5 deg tilt 2024-04-30 17-42-51.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 6 deg w neg 15 deg tilt 2024-04-30 17-48-28.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 13 deg w neg 15 deg tilt 2024-04-30 17-50-12.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 20 deg w neg 15 deg tilt 2024-04-30 17-51-04.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 27 deg w neg 15 deg tilt 2024-04-30 17-51-46.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 33 deg w neg 15 deg tilt 2024-04-30 17-52-37.png’,…
‘F:ProgramsARESIHSS ProgramPicturesLens Distortion MappingIMX323 SN 0001neg 39 deg w neg 15 deg tilt 2024-04-30 17-53-44.png’,…
};
% Detect checkerboards in images
[imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(imageFileNames);
imageFileNames = imageFileNames(imagesUsed);
% Read the first image to obtain image size
originalImage = imread(imageFileNames{1});
[mrows, ncols, ~] = size(originalImage);
% Generate world coordinates of the corners of the squares
squareSize = 1.270000e+01; % in units of ‘millimeters’
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
% Calibrate the camera
[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, …
‘EstimateSkew’, true, ‘EstimateTangentialDistortion’, true, …
‘NumRadialDistortionCoefficients’, 3, ‘WorldUnits’, ‘millimeters’, …
‘InitialIntrinsicMatrix’, [], ‘InitialRadialDistortion’, [], …
‘ImageSize’, [mrows, ncols]);
% View reprojection errors
h1=figure; showReprojectionErrors(cameraParams);
% Visualize pattern locations
h2=figure; showExtrinsics(cameraParams, ‘CameraCentric’);
% Display parameter estimation errors
displayErrors(estimationErrors, cameraParams);
% For example, you can use the calibration data to remove effects of lens distortion.
undistortedImage = undistortImage(originalImage, cameraParams);
% See additional examples of how to use the calibration data. At the prompt type:
% showdemo(‘MeasuringPlanarObjectsExample’)
% showdemo(‘StructureFromMotionExample’)
JUst not sure how to get from is Highlghted code above to an answer. Is it just a subtraction of cameraParams – original image that wil tell us how to adjust for distotion in post processed maner please?? undistortedimage MATLAB Answers — New Questions
how can I plot a P-v and T-S diagrams in simulink
Hi,
I want to make a Thermo plots like P-v and T-S based on the thermodynamic process I am modeling in simulink.
till now I have been working with the P-H diagram block but I need more details for the process.
are there any blocks for making a plot based on chosen properties? I know I can plot each parameter as time dependet by using SCOP, but that does not help me…
if the plot can be made by adding a code diractly to the main program or by using the MATLAB function block please add a manuall or a wide explanation becausse I have never done that before.
Thank YOU!!Hi,
I want to make a Thermo plots like P-v and T-S based on the thermodynamic process I am modeling in simulink.
till now I have been working with the P-H diagram block but I need more details for the process.
are there any blocks for making a plot based on chosen properties? I know I can plot each parameter as time dependet by using SCOP, but that does not help me…
if the plot can be made by adding a code diractly to the main program or by using the MATLAB function block please add a manuall or a wide explanation becausse I have never done that before.
Thank YOU!! Hi,
I want to make a Thermo plots like P-v and T-S based on the thermodynamic process I am modeling in simulink.
till now I have been working with the P-H diagram block but I need more details for the process.
are there any blocks for making a plot based on chosen properties? I know I can plot each parameter as time dependet by using SCOP, but that does not help me…
if the plot can be made by adding a code diractly to the main program or by using the MATLAB function block please add a manuall or a wide explanation becausse I have never done that before.
Thank YOU!! plotting, model, simulation MATLAB Answers — New Questions
What am I missing here? I have included all the parameters into my script but I still get zero as my answer. See script below
Consider four ponds connected by streams. Initially, the ponds were pristine.
At time t=0, after environmental accident, the second and third ponds are getting polluted with the sources, releasing pollutant substance with the following rates: f2=1 kg/h and f3=4 kg/h. Pollution spreads via the connecting streams to the other ponds, as shown in the Figure.
Formulate associated differential equations in terms of x1(t), x2(t), x3(t) and x4(t) – time functions, describing pollutant amounts in each lake. Solve problem numerically, using ode45 MATLAB procedure, and DETERMINE the amount of pollutant (in kg) in lake #2 towards the end of 48 hours of contamination. For a specific numerical example, take f12/V1=f41/V4=0.05; f23/V2=f34/V3=0.02; f24/V2=0.03 [all in 1/h].
Figure-2: Four ponds #1, #2, #3 and #4 of volumes V1, V2, V3, V4 [all in m^3], connected by streams with specific flow rates f12, f13, f23, f34, f41 [m^3/h].
Here is the script I came up with but when I run it I get zero as my anser. What am I missing?
% Define parameters
f12 = 0.05; % kg/h
f23 = 0.02; % kg/h
f24 = 0.03; % kg/h
f34 = 0.02; % kg/h
V1 = 1; % m^3
V2 = 1; % m^3
V3 = 1; % m^3
% Define time span
tspan = [0 48]; % 48 hours
% Define initial conditions
x0 = [0; 0; 0; 0]; % Initial pollutant amounts in each pond
% Define the function for the system of ODEs
ode_system = @(t, x) [
-f12/V1 * x(1);
f12/V1 * x(1) – (f23/V2 + f24/V2) * x(2);
f23/V2 * x(2) – f34/V3 * x(3);
f24/V2 * x(2) + f34/V3 * x(3);
];
% Solve the system of ODEs
[t, x] = ode45(ode_system, tspan, x0);
% Extract pollutant amount in pond 2 at the end of 48 hours
x2_end = x(end, 2);
% Display result
fprintf(‘Pollutant amount in pond 2 at the end of 48 hours: %.4f kgn’, x2_end);
% Plot results
plot(t, x);
xlabel(‘Time (hours)’);
ylabel(‘Pollutant amount (kg)’);
legend(‘Pond 1’, ‘Pond 2’, ‘Pond 3’, ‘Pond 4’);
title(‘Pollutant Amounts in Ponds Over Time’);Consider four ponds connected by streams. Initially, the ponds were pristine.
At time t=0, after environmental accident, the second and third ponds are getting polluted with the sources, releasing pollutant substance with the following rates: f2=1 kg/h and f3=4 kg/h. Pollution spreads via the connecting streams to the other ponds, as shown in the Figure.
Formulate associated differential equations in terms of x1(t), x2(t), x3(t) and x4(t) – time functions, describing pollutant amounts in each lake. Solve problem numerically, using ode45 MATLAB procedure, and DETERMINE the amount of pollutant (in kg) in lake #2 towards the end of 48 hours of contamination. For a specific numerical example, take f12/V1=f41/V4=0.05; f23/V2=f34/V3=0.02; f24/V2=0.03 [all in 1/h].
Figure-2: Four ponds #1, #2, #3 and #4 of volumes V1, V2, V3, V4 [all in m^3], connected by streams with specific flow rates f12, f13, f23, f34, f41 [m^3/h].
Here is the script I came up with but when I run it I get zero as my anser. What am I missing?
% Define parameters
f12 = 0.05; % kg/h
f23 = 0.02; % kg/h
f24 = 0.03; % kg/h
f34 = 0.02; % kg/h
V1 = 1; % m^3
V2 = 1; % m^3
V3 = 1; % m^3
% Define time span
tspan = [0 48]; % 48 hours
% Define initial conditions
x0 = [0; 0; 0; 0]; % Initial pollutant amounts in each pond
% Define the function for the system of ODEs
ode_system = @(t, x) [
-f12/V1 * x(1);
f12/V1 * x(1) – (f23/V2 + f24/V2) * x(2);
f23/V2 * x(2) – f34/V3 * x(3);
f24/V2 * x(2) + f34/V3 * x(3);
];
% Solve the system of ODEs
[t, x] = ode45(ode_system, tspan, x0);
% Extract pollutant amount in pond 2 at the end of 48 hours
x2_end = x(end, 2);
% Display result
fprintf(‘Pollutant amount in pond 2 at the end of 48 hours: %.4f kgn’, x2_end);
% Plot results
plot(t, x);
xlabel(‘Time (hours)’);
ylabel(‘Pollutant amount (kg)’);
legend(‘Pond 1’, ‘Pond 2’, ‘Pond 3’, ‘Pond 4’);
title(‘Pollutant Amounts in Ponds Over Time’); Consider four ponds connected by streams. Initially, the ponds were pristine.
At time t=0, after environmental accident, the second and third ponds are getting polluted with the sources, releasing pollutant substance with the following rates: f2=1 kg/h and f3=4 kg/h. Pollution spreads via the connecting streams to the other ponds, as shown in the Figure.
Formulate associated differential equations in terms of x1(t), x2(t), x3(t) and x4(t) – time functions, describing pollutant amounts in each lake. Solve problem numerically, using ode45 MATLAB procedure, and DETERMINE the amount of pollutant (in kg) in lake #2 towards the end of 48 hours of contamination. For a specific numerical example, take f12/V1=f41/V4=0.05; f23/V2=f34/V3=0.02; f24/V2=0.03 [all in 1/h].
Figure-2: Four ponds #1, #2, #3 and #4 of volumes V1, V2, V3, V4 [all in m^3], connected by streams with specific flow rates f12, f13, f23, f34, f41 [m^3/h].
Here is the script I came up with but when I run it I get zero as my anser. What am I missing?
% Define parameters
f12 = 0.05; % kg/h
f23 = 0.02; % kg/h
f24 = 0.03; % kg/h
f34 = 0.02; % kg/h
V1 = 1; % m^3
V2 = 1; % m^3
V3 = 1; % m^3
% Define time span
tspan = [0 48]; % 48 hours
% Define initial conditions
x0 = [0; 0; 0; 0]; % Initial pollutant amounts in each pond
% Define the function for the system of ODEs
ode_system = @(t, x) [
-f12/V1 * x(1);
f12/V1 * x(1) – (f23/V2 + f24/V2) * x(2);
f23/V2 * x(2) – f34/V3 * x(3);
f24/V2 * x(2) + f34/V3 * x(3);
];
% Solve the system of ODEs
[t, x] = ode45(ode_system, tspan, x0);
% Extract pollutant amount in pond 2 at the end of 48 hours
x2_end = x(end, 2);
% Display result
fprintf(‘Pollutant amount in pond 2 at the end of 48 hours: %.4f kgn’, x2_end);
% Plot results
plot(t, x);
xlabel(‘Time (hours)’);
ylabel(‘Pollutant amount (kg)’);
legend(‘Pond 1’, ‘Pond 2’, ‘Pond 3’, ‘Pond 4’);
title(‘Pollutant Amounts in Ponds Over Time’); 1st order ordinary differential equations MATLAB Answers — New Questions