Tag Archives: matlab
How can I get MATLAB to detect my GigE vision camera?
I am trying to operate a GigE vision camera manufactured by IDS through MATLAB. I installed Image Aquisition Toolbox and the support package for GigE but the gigecamlist function won’t return me anything. I followed the configuration guide on https://www.mathworks.com/help/imaq/configure-gigabit-ethernet-network-adapter-on-windows.html, but it didn’t solve the issue. I tried turing off firewall and that didn’t solve either. The camera itself does work and can be operated with the software from IDS. What could be the issue?I am trying to operate a GigE vision camera manufactured by IDS through MATLAB. I installed Image Aquisition Toolbox and the support package for GigE but the gigecamlist function won’t return me anything. I followed the configuration guide on https://www.mathworks.com/help/imaq/configure-gigabit-ethernet-network-adapter-on-windows.html, but it didn’t solve the issue. I tried turing off firewall and that didn’t solve either. The camera itself does work and can be operated with the software from IDS. What could be the issue? I am trying to operate a GigE vision camera manufactured by IDS through MATLAB. I installed Image Aquisition Toolbox and the support package for GigE but the gigecamlist function won’t return me anything. I followed the configuration guide on https://www.mathworks.com/help/imaq/configure-gigabit-ethernet-network-adapter-on-windows.html, but it didn’t solve the issue. I tried turing off firewall and that didn’t solve either. The camera itself does work and can be operated with the software from IDS. What could be the issue? image acquisition, computer vision MATLAB Answers — New Questions
NI9401 Pulse Generation and Digital Output same time
Hey all,
I want to drive a stepper controller (TRINAMICS) using the NI 9401. I know that NI 9401 is capable of generating pulse which can be used for the "CLK" resp. "STEP" signal for the stepper controller. Beside the CLK signal I also have to provide digital signals for "DIR" (direction) and "EN" (enable). Is it possible to generate pulsed signal and "constant" digital output signals same time using the NI 9401 ?
My recent approach is attached below, which is not working.
Thank you !
close all;
clear;
clc;
devID_NI9401="cDAQ1Mod1";
daqObj=daq(‘ni’);
chCLK=addoutput(daqObj,devID_NI9401,"ctr0","PulseGeneration");
chCLK.Frequency = 1000;
chCLK.DutyCycle = 0.5;
chDO=addoutput(daqObj,devID_NI9401,"port0/line2","Digital");
write(daqObj,ones(500,1));
start(daqObj,"continuous")Hey all,
I want to drive a stepper controller (TRINAMICS) using the NI 9401. I know that NI 9401 is capable of generating pulse which can be used for the "CLK" resp. "STEP" signal for the stepper controller. Beside the CLK signal I also have to provide digital signals for "DIR" (direction) and "EN" (enable). Is it possible to generate pulsed signal and "constant" digital output signals same time using the NI 9401 ?
My recent approach is attached below, which is not working.
Thank you !
close all;
clear;
clc;
devID_NI9401="cDAQ1Mod1";
daqObj=daq(‘ni’);
chCLK=addoutput(daqObj,devID_NI9401,"ctr0","PulseGeneration");
chCLK.Frequency = 1000;
chCLK.DutyCycle = 0.5;
chDO=addoutput(daqObj,devID_NI9401,"port0/line2","Digital");
write(daqObj,ones(500,1));
start(daqObj,"continuous") Hey all,
I want to drive a stepper controller (TRINAMICS) using the NI 9401. I know that NI 9401 is capable of generating pulse which can be used for the "CLK" resp. "STEP" signal for the stepper controller. Beside the CLK signal I also have to provide digital signals for "DIR" (direction) and "EN" (enable). Is it possible to generate pulsed signal and "constant" digital output signals same time using the NI 9401 ?
My recent approach is attached below, which is not working.
Thank you !
close all;
clear;
clc;
devID_NI9401="cDAQ1Mod1";
daqObj=daq(‘ni’);
chCLK=addoutput(daqObj,devID_NI9401,"ctr0","PulseGeneration");
chCLK.Frequency = 1000;
chCLK.DutyCycle = 0.5;
chDO=addoutput(daqObj,devID_NI9401,"port0/line2","Digital");
write(daqObj,ones(500,1));
start(daqObj,"continuous") daq, matlab MATLAB Answers — New Questions
Error when using resample and smooth surfaces in CAT12
I am trying to use CAT12 to make do surface based morphometry. I am trying to load my cortical thickness maps in the resample and smooth function, but when doing that I get this error when trying to load the files clicking on ‘specify’:
Index exceeds the number of array elements. Index must not exceed 0.
Error in cat_surf_info (line 241)
sinfo(i).side = ff2(hemi_ind(1):hemi_ind(1)+1);
Error in cat_conf_stools>vout_surf_resamp (line 2245)
sinfo = cat_surf_info(job.data_surf{i});
Error in cat_conf_stools>@(job)vout_surf_resamp(job) (line 1275)
surfresamp.vout = @(job) vout_surf_resamp(job);
Error in cfg_exbranch/harvest (line 99)
item.sout = feval(item.vout, val);
Error in cfg_util (line 704)
[tag, val, u3, u4, u5, jobs(cjob).cj] = harvest(subsref(jobs(cjob).cj, …
Error in cfg_ui_util>local_setvaledit (line 661)
cfg_util(‘harvest’, ciid{1:end-1});
Error in cfg_ui_util>@(nval)local_setvaledit(ciid,nval,dflag) (line 275)
udvalshow.setvalcb = @(nval)local_setvaledit(ciid, nval, dflag);
Error in cfg_ui_util (line 454)
feval(udvalshow.setvalcb, val);
Error in cfg_ui>local_valedit_EditValue (line 404)
cfg_ui_util(‘valedit_EditValue’, ciid, itemname, val);
Error in cfg_ui>module_Callback (line 978)
local_valedit_EditValue(hObject);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in cfg_ui (line 53)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)cfg_ui(‘module_Callback’,hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
What can I do to fix this error? I am using Matlab 2022a with SPM12 and CAT12.I am trying to use CAT12 to make do surface based morphometry. I am trying to load my cortical thickness maps in the resample and smooth function, but when doing that I get this error when trying to load the files clicking on ‘specify’:
Index exceeds the number of array elements. Index must not exceed 0.
Error in cat_surf_info (line 241)
sinfo(i).side = ff2(hemi_ind(1):hemi_ind(1)+1);
Error in cat_conf_stools>vout_surf_resamp (line 2245)
sinfo = cat_surf_info(job.data_surf{i});
Error in cat_conf_stools>@(job)vout_surf_resamp(job) (line 1275)
surfresamp.vout = @(job) vout_surf_resamp(job);
Error in cfg_exbranch/harvest (line 99)
item.sout = feval(item.vout, val);
Error in cfg_util (line 704)
[tag, val, u3, u4, u5, jobs(cjob).cj] = harvest(subsref(jobs(cjob).cj, …
Error in cfg_ui_util>local_setvaledit (line 661)
cfg_util(‘harvest’, ciid{1:end-1});
Error in cfg_ui_util>@(nval)local_setvaledit(ciid,nval,dflag) (line 275)
udvalshow.setvalcb = @(nval)local_setvaledit(ciid, nval, dflag);
Error in cfg_ui_util (line 454)
feval(udvalshow.setvalcb, val);
Error in cfg_ui>local_valedit_EditValue (line 404)
cfg_ui_util(‘valedit_EditValue’, ciid, itemname, val);
Error in cfg_ui>module_Callback (line 978)
local_valedit_EditValue(hObject);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in cfg_ui (line 53)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)cfg_ui(‘module_Callback’,hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
What can I do to fix this error? I am using Matlab 2022a with SPM12 and CAT12. I am trying to use CAT12 to make do surface based morphometry. I am trying to load my cortical thickness maps in the resample and smooth function, but when doing that I get this error when trying to load the files clicking on ‘specify’:
Index exceeds the number of array elements. Index must not exceed 0.
Error in cat_surf_info (line 241)
sinfo(i).side = ff2(hemi_ind(1):hemi_ind(1)+1);
Error in cat_conf_stools>vout_surf_resamp (line 2245)
sinfo = cat_surf_info(job.data_surf{i});
Error in cat_conf_stools>@(job)vout_surf_resamp(job) (line 1275)
surfresamp.vout = @(job) vout_surf_resamp(job);
Error in cfg_exbranch/harvest (line 99)
item.sout = feval(item.vout, val);
Error in cfg_util (line 704)
[tag, val, u3, u4, u5, jobs(cjob).cj] = harvest(subsref(jobs(cjob).cj, …
Error in cfg_ui_util>local_setvaledit (line 661)
cfg_util(‘harvest’, ciid{1:end-1});
Error in cfg_ui_util>@(nval)local_setvaledit(ciid,nval,dflag) (line 275)
udvalshow.setvalcb = @(nval)local_setvaledit(ciid, nval, dflag);
Error in cfg_ui_util (line 454)
feval(udvalshow.setvalcb, val);
Error in cfg_ui>local_valedit_EditValue (line 404)
cfg_ui_util(‘valedit_EditValue’, ciid, itemname, val);
Error in cfg_ui>module_Callback (line 978)
local_valedit_EditValue(hObject);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in cfg_ui (line 53)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)cfg_ui(‘module_Callback’,hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
What can I do to fix this error? I am using Matlab 2022a with SPM12 and CAT12. cat12, spm MATLAB Answers — New Questions
License problem only when running Matlab in a csh script on Linux
Hi everyone,
I wrote a matlab program for automatc generation of some plots. I use the "shaperead" function, as well as other functionalities and I have installed the Mapping toolbox as well as all toolboxes needed. When I launch my program in the matlab command window it runs.
Anyway, when I launch it within a .csh script I have the following error:
"shaperead requires Mapping Toolbox"
I found here a simila problem, where it was suggested to reinstall and run again the mathworksservicehost toolkit.
I did it and it worked for one day, but after two days I have the same problem.
This solution is not suitable when you have to schedule automatic processes.
I use an Ubuntu 20 OS and MatlabR2024a academic license
Thank you for your helpHi everyone,
I wrote a matlab program for automatc generation of some plots. I use the "shaperead" function, as well as other functionalities and I have installed the Mapping toolbox as well as all toolboxes needed. When I launch my program in the matlab command window it runs.
Anyway, when I launch it within a .csh script I have the following error:
"shaperead requires Mapping Toolbox"
I found here a simila problem, where it was suggested to reinstall and run again the mathworksservicehost toolkit.
I did it and it worked for one day, but after two days I have the same problem.
This solution is not suitable when you have to schedule automatic processes.
I use an Ubuntu 20 OS and MatlabR2024a academic license
Thank you for your help Hi everyone,
I wrote a matlab program for automatc generation of some plots. I use the "shaperead" function, as well as other functionalities and I have installed the Mapping toolbox as well as all toolboxes needed. When I launch my program in the matlab command window it runs.
Anyway, when I launch it within a .csh script I have the following error:
"shaperead requires Mapping Toolbox"
I found here a simila problem, where it was suggested to reinstall and run again the mathworksservicehost toolkit.
I did it and it worked for one day, but after two days I have the same problem.
This solution is not suitable when you have to schedule automatic processes.
I use an Ubuntu 20 OS and MatlabR2024a academic license
Thank you for your help license, linux, ubuntu, mathworksservicehost, mapping toolbox MATLAB Answers — New Questions
Custom training loop and parameters for semantic segmentation problem
Good day
I have been working on a semantic segmentation problem using the Deep Learning Toolbox, with the unetLayers method.
But I now need to tune some parameters that I trust are not accessible through the toolbox. I would like to:
Use a custom loss function, sum of a weighted focal loss and a dice loss.
Augment data over each epoch, and if possible, use a custom augmentation method, called RLR (Random Local Rotation).
Implement a learning rate based on the ‘One cycle’ method.
Track the training progress with as much details as possible.
Here is my base code; that worked for training the Unet:
[imds,pxds] = create_ds(folders);
indicesTest = 1:floor(length(imds.Files)/10);
testImds = subset(imds,indicesTest);
testPxds = subset(pxds,indicesTest);
dsTest = combine(testImds,testPxds);
indicesTraining = floor(length(imds.Files)/10):length(imds.Files);
trainingImds = subset(imds,indicesTraining);
trainingPxds = subset(pxds,indicesTraining);
dsTraining = combine(trainingImds,trainingPxds);
imageSize = [128 128 3];
numClasses = 2;
unetNetwork = unetLayers(imageSize,numClasses,EncoderDepth = 3);
opts = trainingOptions ("rmsprop", …
InitialLearnRate = 1e-3, …
MaxEpochs = 40, …
MiniBatchSize = 32, …
VerboseFrequency = 10, …
Plots = "training-progress", …
Shuffle="every-epoch", …
ValidationData = dsTest, …
ValidationFrequency=10, …
OutputNetwork = "best-validation-loss" )
currentNet = trainNetwork(dsTraining,unetNetwork,opts)
create_ds is a function that returns two datastores. imds contains the RGB images and pxds contains categorical images with two classes, that are the masks to each image from imds.
The RLR function returns [image,label], the RGB and categorical images that have been geometrically modified (the dimensions and type are conserved).
Here is the function that returns the custom loss:
function loss = combinedLoss(Y, T, alpha, gamma)
epsilon = 1e-6;
p = sigmoid(Y);
lossPos = -alpha * (1 – p).^gamma .* T .* log(p + epsilon);
lossNeg = -(1 – alpha) * p.^gamma .* (1 – T) .* log(1 – p + epsilon);
weightedFocalLoss = mean(lossPos + lossNeg, ‘all’);
intersection = sum(Y .* T, ‘all’);
union = sum(Y, ‘all’) + sum(T, ‘all’);
diceCoeff = (2 * intersection + epsilon) / (union + epsilon);
diceLoss = 1 – diceCoeff;
loss = weightedFocalLoss + diceLoss;
end
I have reviewed the guides that explain how to create a custom training loop:
‘ Train network using custom training loop’ and ‘Monitor custom training loop progress’ -and some others- several times, but I still don’t get how to adapt the examples to my semantic segmentation problem, and with the correct behaviour for my input data.
I don’t think sharing the fragments of code I have tried to compose would be helpful, as they are very far from functional.
Any help on the matter, whether contributing to answer my question partially, or completely, would be greatly appreciated.
Have a nice week-end!Good day
I have been working on a semantic segmentation problem using the Deep Learning Toolbox, with the unetLayers method.
But I now need to tune some parameters that I trust are not accessible through the toolbox. I would like to:
Use a custom loss function, sum of a weighted focal loss and a dice loss.
Augment data over each epoch, and if possible, use a custom augmentation method, called RLR (Random Local Rotation).
Implement a learning rate based on the ‘One cycle’ method.
Track the training progress with as much details as possible.
Here is my base code; that worked for training the Unet:
[imds,pxds] = create_ds(folders);
indicesTest = 1:floor(length(imds.Files)/10);
testImds = subset(imds,indicesTest);
testPxds = subset(pxds,indicesTest);
dsTest = combine(testImds,testPxds);
indicesTraining = floor(length(imds.Files)/10):length(imds.Files);
trainingImds = subset(imds,indicesTraining);
trainingPxds = subset(pxds,indicesTraining);
dsTraining = combine(trainingImds,trainingPxds);
imageSize = [128 128 3];
numClasses = 2;
unetNetwork = unetLayers(imageSize,numClasses,EncoderDepth = 3);
opts = trainingOptions ("rmsprop", …
InitialLearnRate = 1e-3, …
MaxEpochs = 40, …
MiniBatchSize = 32, …
VerboseFrequency = 10, …
Plots = "training-progress", …
Shuffle="every-epoch", …
ValidationData = dsTest, …
ValidationFrequency=10, …
OutputNetwork = "best-validation-loss" )
currentNet = trainNetwork(dsTraining,unetNetwork,opts)
create_ds is a function that returns two datastores. imds contains the RGB images and pxds contains categorical images with two classes, that are the masks to each image from imds.
The RLR function returns [image,label], the RGB and categorical images that have been geometrically modified (the dimensions and type are conserved).
Here is the function that returns the custom loss:
function loss = combinedLoss(Y, T, alpha, gamma)
epsilon = 1e-6;
p = sigmoid(Y);
lossPos = -alpha * (1 – p).^gamma .* T .* log(p + epsilon);
lossNeg = -(1 – alpha) * p.^gamma .* (1 – T) .* log(1 – p + epsilon);
weightedFocalLoss = mean(lossPos + lossNeg, ‘all’);
intersection = sum(Y .* T, ‘all’);
union = sum(Y, ‘all’) + sum(T, ‘all’);
diceCoeff = (2 * intersection + epsilon) / (union + epsilon);
diceLoss = 1 – diceCoeff;
loss = weightedFocalLoss + diceLoss;
end
I have reviewed the guides that explain how to create a custom training loop:
‘ Train network using custom training loop’ and ‘Monitor custom training loop progress’ -and some others- several times, but I still don’t get how to adapt the examples to my semantic segmentation problem, and with the correct behaviour for my input data.
I don’t think sharing the fragments of code I have tried to compose would be helpful, as they are very far from functional.
Any help on the matter, whether contributing to answer my question partially, or completely, would be greatly appreciated.
Have a nice week-end! Good day
I have been working on a semantic segmentation problem using the Deep Learning Toolbox, with the unetLayers method.
But I now need to tune some parameters that I trust are not accessible through the toolbox. I would like to:
Use a custom loss function, sum of a weighted focal loss and a dice loss.
Augment data over each epoch, and if possible, use a custom augmentation method, called RLR (Random Local Rotation).
Implement a learning rate based on the ‘One cycle’ method.
Track the training progress with as much details as possible.
Here is my base code; that worked for training the Unet:
[imds,pxds] = create_ds(folders);
indicesTest = 1:floor(length(imds.Files)/10);
testImds = subset(imds,indicesTest);
testPxds = subset(pxds,indicesTest);
dsTest = combine(testImds,testPxds);
indicesTraining = floor(length(imds.Files)/10):length(imds.Files);
trainingImds = subset(imds,indicesTraining);
trainingPxds = subset(pxds,indicesTraining);
dsTraining = combine(trainingImds,trainingPxds);
imageSize = [128 128 3];
numClasses = 2;
unetNetwork = unetLayers(imageSize,numClasses,EncoderDepth = 3);
opts = trainingOptions ("rmsprop", …
InitialLearnRate = 1e-3, …
MaxEpochs = 40, …
MiniBatchSize = 32, …
VerboseFrequency = 10, …
Plots = "training-progress", …
Shuffle="every-epoch", …
ValidationData = dsTest, …
ValidationFrequency=10, …
OutputNetwork = "best-validation-loss" )
currentNet = trainNetwork(dsTraining,unetNetwork,opts)
create_ds is a function that returns two datastores. imds contains the RGB images and pxds contains categorical images with two classes, that are the masks to each image from imds.
The RLR function returns [image,label], the RGB and categorical images that have been geometrically modified (the dimensions and type are conserved).
Here is the function that returns the custom loss:
function loss = combinedLoss(Y, T, alpha, gamma)
epsilon = 1e-6;
p = sigmoid(Y);
lossPos = -alpha * (1 – p).^gamma .* T .* log(p + epsilon);
lossNeg = -(1 – alpha) * p.^gamma .* (1 – T) .* log(1 – p + epsilon);
weightedFocalLoss = mean(lossPos + lossNeg, ‘all’);
intersection = sum(Y .* T, ‘all’);
union = sum(Y, ‘all’) + sum(T, ‘all’);
diceCoeff = (2 * intersection + epsilon) / (union + epsilon);
diceLoss = 1 – diceCoeff;
loss = weightedFocalLoss + diceLoss;
end
I have reviewed the guides that explain how to create a custom training loop:
‘ Train network using custom training loop’ and ‘Monitor custom training loop progress’ -and some others- several times, but I still don’t get how to adapt the examples to my semantic segmentation problem, and with the correct behaviour for my input data.
I don’t think sharing the fragments of code I have tried to compose would be helpful, as they are very far from functional.
Any help on the matter, whether contributing to answer my question partially, or completely, would be greatly appreciated.
Have a nice week-end! image segmentation, deep learning, unet MATLAB Answers — New Questions
Is it possible that ploting bode diagram without transfer fuction?
Hi everyone,
Is it possible that ploting bode diagram without transfer fuction?
I have some values of the Power and the Speed as inputs and some output values in excel format. However the transfer fuction of the system has not been defined.
Are there any one who knows any method or code to plotting bode diagram without transfer function?Hi everyone,
Is it possible that ploting bode diagram without transfer fuction?
I have some values of the Power and the Speed as inputs and some output values in excel format. However the transfer fuction of the system has not been defined.
Are there any one who knows any method or code to plotting bode diagram without transfer function? Hi everyone,
Is it possible that ploting bode diagram without transfer fuction?
I have some values of the Power and the Speed as inputs and some output values in excel format. However the transfer fuction of the system has not been defined.
Are there any one who knows any method or code to plotting bode diagram without transfer function? bodeplot, bode plot, transfer function, step response, frequency response MATLAB Answers — New Questions
Want to check the program is technically right and work accurately?
I have two signals, T_para and T_per (5*17*20) loaded from directory, I coded this program to do the following tasks:
Calculate the cost function
Apply interpolation to increase the density of a and r
Minimize the cost function using optimiztion method (Grid search method)
Plot figures with minimum cost value
Please check if there is a mistake technically or in the structure. My program code is:
clear all; clc; close all;
cloud = ‘Homo’;
T_para = zeros(5, 17, 20);
T_per = zeros(5, 17, 20);
% Initialize matrices
T_para_noisy = zeros(5, 17, 20);
T_per_noisy = zeros(5, 17, 20);
% Function to add AWGN
add_noise = @(signal, snr) awgn(signal, snr, ‘measured’);
% Define the cost function
% cost_function = @(original, noisy) sum((original(:) – noisy(:)).^2) / numel(original);
cost_function = @(original, noisy, variance) sum(((original(:) – noisy(:))./ (var(original(:)))).^2);
% Initialize arrays to store the optimal values and global minimum cost
lookup_table = [];
lookup_table_interp = [];
% Initialize global minimum cost values
global_min_cost = Inf;
optimal_a= 0;
optimal_r = 0;
% Define ranges for a and r
a_range = 0.01:0.01:0.05;
r_range = 4:20;
% Initialize cost matrix to store costs for all combinations of a and r
cost_matrix = zeros(length(a_range), length(r_range));
for h = 1000:1000:4000
for fov = [0.2, 0.5, 1, 2, 5, 10]
for a_idx = 1:length(a_range)
for r_idx = 1:length(r_range)
a = a_range(a_idx);
r = r_range(r_idx);
load([‘./Tabledata_’, cloud, ‘/’, num2str(h), ‘m-‘, num2str(fov), ‘mrad/TABLE.mat’]);
% Add noise to the signals
T_para_noisy = add_noise(T_para, 30); % 20dB SNR
T_per_noisy = add_noise(T_per, 30);
% Calculate the variance of the original signals
var_T_para = var(T_para, 0, ‘all’);
var_T_per = var(T_per, 0, ‘all’);
% Calculate the cost for each pair of original and noisy signals
cost_para = cost_function(T_para, T_para_noisy, var_T_para);
cost_per = cost_function(T_per, T_per_noisy, var_T_per);
% Sum the costs
total_cost = cost_para + cost_per;
% Store the cost for plotting
cost_matrix(a_idx, r_idx) = total_cost;
% Check if this is the new global minimum
if total_cost < global_min_cost
global_min_cost= total_cost;
optimal_a = a;
optimal_r = r;
end
end
end
% Store the optimal values and global minimum cost in the lookup table
lookup_table = [lookup_table; optimal_a, optimal_r, global_min_cost];
end
end
% Save and display the look-up table for optimal interpolated values
save(‘LookupTable.mat’, ‘lookup_table’);
% Initialize global minimum cost for interpolated values
global_min_cost_interp = Inf;
optimal_a_interp = 0;
optimal_r_interp = 0;
% Define finer gridded interpolant for cost_matrix
a_interp = 0.01:0.001:0.05;
r_interp = 4:0.5:20;
% Define the original and interpolated grids
[a_grid, r_grid] = meshgrid(a_range, r_range);
[a_interp_grid, r_interp_grid] = meshgrid(a_interp, r_interp);
% Transpose the cost_matrix to match the grid dimensions
cost_matrix = cost_matrix’;
% Apply gridded interpolation using spline method
cost_matrix_interp = interp2(a_grid, r_grid, cost_matrix, a_interp_grid, r_interp_grid, ‘spline’);
% Loop through the interpolated grid to find the global minimum
for a_interp_idx = 1:length(a_interp)
for r_interp_idx = 1:length(r_interp)
interpolated_cost = cost_matrix_interp(r_interp_idx, a_interp_idx); % Note the order of indices
% Check if this is the new global minimum
if interpolated_cost < global_min_cost_interp
global_min_cost_interp = interpolated_cost;
optimal_a_interp = a_interp(a_interp_idx);
optimal_r_interp = r_interp(r_interp_idx);
end
end
end
% Add to the lookup table
lookup_table_interp = [lookup_table_interp; optimal_a_interp, optimal_r_interp, global_min_cost_interp];
% Save and display the look-up table for optimal interpolated values
save(‘LookupTable_Interp.mat’, ‘lookup_table_interp’);
disp(‘Global minimum interpolated cost:’);
disp(global_min_cost_interp);
% Normalize the cost_matrix_interp values
min_cost = min(cost_matrix_interp(:));
max_cost = max(cost_matrix_interp(:));
normalized_cost_matrix_interp = (cost_matrix_interp – min_cost) / (max_cost – min_cost);
%%
% Plot the normalized interpolated cost function
figure(1);
surf(a_interp_grid, r_interp_grid, cost_matrix_interp);
shading interp;
colormap parula;
colorbar;
set(gca, ‘color’, ‘w’, ‘FontSize’, 12, ‘LineWidth’, 1, ‘FontWeight’, ‘normal’);
ylabel(‘R_{e} interp (mum)’);
xlabel(‘alpha_{e} interp (m^{-1})’);
zlabel(‘Normalized interpolated cost function’);
title(‘Normalized interpolated CF over alpha_{e} interp and R_{e} interp’);
set(gca, ‘box’, ‘on’, ‘LineWidth’, 1, ‘FontName’, ‘Arial’, ‘FontSmoothing’, ‘on’);
set(gca, ‘xlim’, [0.01 0.05], ‘xtick’, [0.01 0.02 0.03 0.04 0.05], ‘ylim’, [4 20], ‘ytick’, [4 8 12 16 20]);
grid on;
hold on;
% Create a meshgrid for plotting
[A, R] = meshgrid(a_interp, r_interp);
% Reshape the matrices to vectors for plotting
A_vector = reshape(A, [], 1);
R_vector = reshape(R, [], 1);
Re_cost_matrix_interp = reshape(cost_matrix_interp, [], 1);
% Find the global minimum in the interpolated cost matrix
[global_min_cost_interp, min_idx] = min(Re_cost_matrix_interp);
optimal_a_interp = A_vector(min_idx);
optimal_r_interp = R_vector(min_idx);
% Mark the minimum point
hold on;
surf_handle=plot3(optimal_a_interp, optimal_r_interp, global_min_cost_interp, ‘ro’, ‘MarkerSize’, 12, ‘MarkerFaceColor’, ‘r’);
view(3); % Set the viewing angle to 3D
% Bring the red point to the front
uistack(surf_handle, ‘top’); % Bring the red point to the front
hold off;
% Plot the 2D Contour Plot of the interpolated cost function
figure(2);
contourf(a_interp_grid, r_interp_grid, normalized_cost_matrix_interp, 20);
colorbar;
xlabel(‘alpha_{e} interp (m^{-1})’);
ylabel(‘R_{e} interp (mum)’);
title(‘2D Contour Plot of interpolated normalized CF’);
set(gca,’FontSize’, 12, ‘LineWidth’, 1, ‘FontWeight’, ‘normal’);
set(gca, ‘box’, ‘on’, ‘LineWidth’, 1, ‘FontName’, ‘Arial’, ‘FontSmoothing’, ‘on’);
set(gca, ‘xlim’, [0.01 0.05], ‘xtick’, [0.01 0.02 0.03 0.04 0.05], ‘ylim’, [4 20], ‘ytick’, [4 8 12 16 20]);
hold on;
plot(optimal_a_interp, optimal_r_interp, ‘ro’, ‘MarkerSize’, 12, ‘MarkerFaceColor’, ‘r’); % Mark the minimum point from interpolated grid search
% plot(optimal_a, optimal_r, ‘bo’, ‘MarkerSize’, 10, ‘LineWidth’, 2); % Mark the minimum point from original grid search
hold off;
% Plot the normalized cost values
figure(3);
scatter3(R_vector, A_vector, Re_cost_matrix_interp, ‘filled’);
xlabel(‘R_{e} interp (mum)’);
ylabel(‘alpha_{e} interp (m^{-1})’);
zlabel(‘Interpolated cost function’);
title(‘Normalized interpolated CF over alpha_{e} interp and R_{e} interp’);
set(gca, ‘color’, ‘w’, ‘FontSize’, 12, ‘LineWidth’, 1, ‘FontWeight’, ‘normal’);
set(gca, ‘box’, ‘on’, ‘FontName’, ‘Arial’, ‘FontSmoothing’, ‘on’);
set(gca, ‘ylim’, [0.01 0.05], ‘ytick’, [0.01 0.02 0.03 0.04 0.05], ‘xlim’, [4 20], ‘xtick’, [4 8 12 16 20]);
grid on;
hold on;
% Set the view angle
view(60, 40); % Adjust the view angles to see the plot clearly
% Mark the minimum point with a circle
surf_handle = plot3(optimal_r_interp, optimal_a_interp, global_min_cost_interp, ‘ro’, ‘MarkerSize’, 12, ‘MarkerFaceColor’, ‘r’);
% Bring the red point to the front
uistack(surf_handle, ‘top’); % Bring the red point to the front
hold off;I have two signals, T_para and T_per (5*17*20) loaded from directory, I coded this program to do the following tasks:
Calculate the cost function
Apply interpolation to increase the density of a and r
Minimize the cost function using optimiztion method (Grid search method)
Plot figures with minimum cost value
Please check if there is a mistake technically or in the structure. My program code is:
clear all; clc; close all;
cloud = ‘Homo’;
T_para = zeros(5, 17, 20);
T_per = zeros(5, 17, 20);
% Initialize matrices
T_para_noisy = zeros(5, 17, 20);
T_per_noisy = zeros(5, 17, 20);
% Function to add AWGN
add_noise = @(signal, snr) awgn(signal, snr, ‘measured’);
% Define the cost function
% cost_function = @(original, noisy) sum((original(:) – noisy(:)).^2) / numel(original);
cost_function = @(original, noisy, variance) sum(((original(:) – noisy(:))./ (var(original(:)))).^2);
% Initialize arrays to store the optimal values and global minimum cost
lookup_table = [];
lookup_table_interp = [];
% Initialize global minimum cost values
global_min_cost = Inf;
optimal_a= 0;
optimal_r = 0;
% Define ranges for a and r
a_range = 0.01:0.01:0.05;
r_range = 4:20;
% Initialize cost matrix to store costs for all combinations of a and r
cost_matrix = zeros(length(a_range), length(r_range));
for h = 1000:1000:4000
for fov = [0.2, 0.5, 1, 2, 5, 10]
for a_idx = 1:length(a_range)
for r_idx = 1:length(r_range)
a = a_range(a_idx);
r = r_range(r_idx);
load([‘./Tabledata_’, cloud, ‘/’, num2str(h), ‘m-‘, num2str(fov), ‘mrad/TABLE.mat’]);
% Add noise to the signals
T_para_noisy = add_noise(T_para, 30); % 20dB SNR
T_per_noisy = add_noise(T_per, 30);
% Calculate the variance of the original signals
var_T_para = var(T_para, 0, ‘all’);
var_T_per = var(T_per, 0, ‘all’);
% Calculate the cost for each pair of original and noisy signals
cost_para = cost_function(T_para, T_para_noisy, var_T_para);
cost_per = cost_function(T_per, T_per_noisy, var_T_per);
% Sum the costs
total_cost = cost_para + cost_per;
% Store the cost for plotting
cost_matrix(a_idx, r_idx) = total_cost;
% Check if this is the new global minimum
if total_cost < global_min_cost
global_min_cost= total_cost;
optimal_a = a;
optimal_r = r;
end
end
end
% Store the optimal values and global minimum cost in the lookup table
lookup_table = [lookup_table; optimal_a, optimal_r, global_min_cost];
end
end
% Save and display the look-up table for optimal interpolated values
save(‘LookupTable.mat’, ‘lookup_table’);
% Initialize global minimum cost for interpolated values
global_min_cost_interp = Inf;
optimal_a_interp = 0;
optimal_r_interp = 0;
% Define finer gridded interpolant for cost_matrix
a_interp = 0.01:0.001:0.05;
r_interp = 4:0.5:20;
% Define the original and interpolated grids
[a_grid, r_grid] = meshgrid(a_range, r_range);
[a_interp_grid, r_interp_grid] = meshgrid(a_interp, r_interp);
% Transpose the cost_matrix to match the grid dimensions
cost_matrix = cost_matrix’;
% Apply gridded interpolation using spline method
cost_matrix_interp = interp2(a_grid, r_grid, cost_matrix, a_interp_grid, r_interp_grid, ‘spline’);
% Loop through the interpolated grid to find the global minimum
for a_interp_idx = 1:length(a_interp)
for r_interp_idx = 1:length(r_interp)
interpolated_cost = cost_matrix_interp(r_interp_idx, a_interp_idx); % Note the order of indices
% Check if this is the new global minimum
if interpolated_cost < global_min_cost_interp
global_min_cost_interp = interpolated_cost;
optimal_a_interp = a_interp(a_interp_idx);
optimal_r_interp = r_interp(r_interp_idx);
end
end
end
% Add to the lookup table
lookup_table_interp = [lookup_table_interp; optimal_a_interp, optimal_r_interp, global_min_cost_interp];
% Save and display the look-up table for optimal interpolated values
save(‘LookupTable_Interp.mat’, ‘lookup_table_interp’);
disp(‘Global minimum interpolated cost:’);
disp(global_min_cost_interp);
% Normalize the cost_matrix_interp values
min_cost = min(cost_matrix_interp(:));
max_cost = max(cost_matrix_interp(:));
normalized_cost_matrix_interp = (cost_matrix_interp – min_cost) / (max_cost – min_cost);
%%
% Plot the normalized interpolated cost function
figure(1);
surf(a_interp_grid, r_interp_grid, cost_matrix_interp);
shading interp;
colormap parula;
colorbar;
set(gca, ‘color’, ‘w’, ‘FontSize’, 12, ‘LineWidth’, 1, ‘FontWeight’, ‘normal’);
ylabel(‘R_{e} interp (mum)’);
xlabel(‘alpha_{e} interp (m^{-1})’);
zlabel(‘Normalized interpolated cost function’);
title(‘Normalized interpolated CF over alpha_{e} interp and R_{e} interp’);
set(gca, ‘box’, ‘on’, ‘LineWidth’, 1, ‘FontName’, ‘Arial’, ‘FontSmoothing’, ‘on’);
set(gca, ‘xlim’, [0.01 0.05], ‘xtick’, [0.01 0.02 0.03 0.04 0.05], ‘ylim’, [4 20], ‘ytick’, [4 8 12 16 20]);
grid on;
hold on;
% Create a meshgrid for plotting
[A, R] = meshgrid(a_interp, r_interp);
% Reshape the matrices to vectors for plotting
A_vector = reshape(A, [], 1);
R_vector = reshape(R, [], 1);
Re_cost_matrix_interp = reshape(cost_matrix_interp, [], 1);
% Find the global minimum in the interpolated cost matrix
[global_min_cost_interp, min_idx] = min(Re_cost_matrix_interp);
optimal_a_interp = A_vector(min_idx);
optimal_r_interp = R_vector(min_idx);
% Mark the minimum point
hold on;
surf_handle=plot3(optimal_a_interp, optimal_r_interp, global_min_cost_interp, ‘ro’, ‘MarkerSize’, 12, ‘MarkerFaceColor’, ‘r’);
view(3); % Set the viewing angle to 3D
% Bring the red point to the front
uistack(surf_handle, ‘top’); % Bring the red point to the front
hold off;
% Plot the 2D Contour Plot of the interpolated cost function
figure(2);
contourf(a_interp_grid, r_interp_grid, normalized_cost_matrix_interp, 20);
colorbar;
xlabel(‘alpha_{e} interp (m^{-1})’);
ylabel(‘R_{e} interp (mum)’);
title(‘2D Contour Plot of interpolated normalized CF’);
set(gca,’FontSize’, 12, ‘LineWidth’, 1, ‘FontWeight’, ‘normal’);
set(gca, ‘box’, ‘on’, ‘LineWidth’, 1, ‘FontName’, ‘Arial’, ‘FontSmoothing’, ‘on’);
set(gca, ‘xlim’, [0.01 0.05], ‘xtick’, [0.01 0.02 0.03 0.04 0.05], ‘ylim’, [4 20], ‘ytick’, [4 8 12 16 20]);
hold on;
plot(optimal_a_interp, optimal_r_interp, ‘ro’, ‘MarkerSize’, 12, ‘MarkerFaceColor’, ‘r’); % Mark the minimum point from interpolated grid search
% plot(optimal_a, optimal_r, ‘bo’, ‘MarkerSize’, 10, ‘LineWidth’, 2); % Mark the minimum point from original grid search
hold off;
% Plot the normalized cost values
figure(3);
scatter3(R_vector, A_vector, Re_cost_matrix_interp, ‘filled’);
xlabel(‘R_{e} interp (mum)’);
ylabel(‘alpha_{e} interp (m^{-1})’);
zlabel(‘Interpolated cost function’);
title(‘Normalized interpolated CF over alpha_{e} interp and R_{e} interp’);
set(gca, ‘color’, ‘w’, ‘FontSize’, 12, ‘LineWidth’, 1, ‘FontWeight’, ‘normal’);
set(gca, ‘box’, ‘on’, ‘FontName’, ‘Arial’, ‘FontSmoothing’, ‘on’);
set(gca, ‘ylim’, [0.01 0.05], ‘ytick’, [0.01 0.02 0.03 0.04 0.05], ‘xlim’, [4 20], ‘xtick’, [4 8 12 16 20]);
grid on;
hold on;
% Set the view angle
view(60, 40); % Adjust the view angles to see the plot clearly
% Mark the minimum point with a circle
surf_handle = plot3(optimal_r_interp, optimal_a_interp, global_min_cost_interp, ‘ro’, ‘MarkerSize’, 12, ‘MarkerFaceColor’, ‘r’);
% Bring the red point to the front
uistack(surf_handle, ‘top’); % Bring the red point to the front
hold off; I have two signals, T_para and T_per (5*17*20) loaded from directory, I coded this program to do the following tasks:
Calculate the cost function
Apply interpolation to increase the density of a and r
Minimize the cost function using optimiztion method (Grid search method)
Plot figures with minimum cost value
Please check if there is a mistake technically or in the structure. My program code is:
clear all; clc; close all;
cloud = ‘Homo’;
T_para = zeros(5, 17, 20);
T_per = zeros(5, 17, 20);
% Initialize matrices
T_para_noisy = zeros(5, 17, 20);
T_per_noisy = zeros(5, 17, 20);
% Function to add AWGN
add_noise = @(signal, snr) awgn(signal, snr, ‘measured’);
% Define the cost function
% cost_function = @(original, noisy) sum((original(:) – noisy(:)).^2) / numel(original);
cost_function = @(original, noisy, variance) sum(((original(:) – noisy(:))./ (var(original(:)))).^2);
% Initialize arrays to store the optimal values and global minimum cost
lookup_table = [];
lookup_table_interp = [];
% Initialize global minimum cost values
global_min_cost = Inf;
optimal_a= 0;
optimal_r = 0;
% Define ranges for a and r
a_range = 0.01:0.01:0.05;
r_range = 4:20;
% Initialize cost matrix to store costs for all combinations of a and r
cost_matrix = zeros(length(a_range), length(r_range));
for h = 1000:1000:4000
for fov = [0.2, 0.5, 1, 2, 5, 10]
for a_idx = 1:length(a_range)
for r_idx = 1:length(r_range)
a = a_range(a_idx);
r = r_range(r_idx);
load([‘./Tabledata_’, cloud, ‘/’, num2str(h), ‘m-‘, num2str(fov), ‘mrad/TABLE.mat’]);
% Add noise to the signals
T_para_noisy = add_noise(T_para, 30); % 20dB SNR
T_per_noisy = add_noise(T_per, 30);
% Calculate the variance of the original signals
var_T_para = var(T_para, 0, ‘all’);
var_T_per = var(T_per, 0, ‘all’);
% Calculate the cost for each pair of original and noisy signals
cost_para = cost_function(T_para, T_para_noisy, var_T_para);
cost_per = cost_function(T_per, T_per_noisy, var_T_per);
% Sum the costs
total_cost = cost_para + cost_per;
% Store the cost for plotting
cost_matrix(a_idx, r_idx) = total_cost;
% Check if this is the new global minimum
if total_cost < global_min_cost
global_min_cost= total_cost;
optimal_a = a;
optimal_r = r;
end
end
end
% Store the optimal values and global minimum cost in the lookup table
lookup_table = [lookup_table; optimal_a, optimal_r, global_min_cost];
end
end
% Save and display the look-up table for optimal interpolated values
save(‘LookupTable.mat’, ‘lookup_table’);
% Initialize global minimum cost for interpolated values
global_min_cost_interp = Inf;
optimal_a_interp = 0;
optimal_r_interp = 0;
% Define finer gridded interpolant for cost_matrix
a_interp = 0.01:0.001:0.05;
r_interp = 4:0.5:20;
% Define the original and interpolated grids
[a_grid, r_grid] = meshgrid(a_range, r_range);
[a_interp_grid, r_interp_grid] = meshgrid(a_interp, r_interp);
% Transpose the cost_matrix to match the grid dimensions
cost_matrix = cost_matrix’;
% Apply gridded interpolation using spline method
cost_matrix_interp = interp2(a_grid, r_grid, cost_matrix, a_interp_grid, r_interp_grid, ‘spline’);
% Loop through the interpolated grid to find the global minimum
for a_interp_idx = 1:length(a_interp)
for r_interp_idx = 1:length(r_interp)
interpolated_cost = cost_matrix_interp(r_interp_idx, a_interp_idx); % Note the order of indices
% Check if this is the new global minimum
if interpolated_cost < global_min_cost_interp
global_min_cost_interp = interpolated_cost;
optimal_a_interp = a_interp(a_interp_idx);
optimal_r_interp = r_interp(r_interp_idx);
end
end
end
% Add to the lookup table
lookup_table_interp = [lookup_table_interp; optimal_a_interp, optimal_r_interp, global_min_cost_interp];
% Save and display the look-up table for optimal interpolated values
save(‘LookupTable_Interp.mat’, ‘lookup_table_interp’);
disp(‘Global minimum interpolated cost:’);
disp(global_min_cost_interp);
% Normalize the cost_matrix_interp values
min_cost = min(cost_matrix_interp(:));
max_cost = max(cost_matrix_interp(:));
normalized_cost_matrix_interp = (cost_matrix_interp – min_cost) / (max_cost – min_cost);
%%
% Plot the normalized interpolated cost function
figure(1);
surf(a_interp_grid, r_interp_grid, cost_matrix_interp);
shading interp;
colormap parula;
colorbar;
set(gca, ‘color’, ‘w’, ‘FontSize’, 12, ‘LineWidth’, 1, ‘FontWeight’, ‘normal’);
ylabel(‘R_{e} interp (mum)’);
xlabel(‘alpha_{e} interp (m^{-1})’);
zlabel(‘Normalized interpolated cost function’);
title(‘Normalized interpolated CF over alpha_{e} interp and R_{e} interp’);
set(gca, ‘box’, ‘on’, ‘LineWidth’, 1, ‘FontName’, ‘Arial’, ‘FontSmoothing’, ‘on’);
set(gca, ‘xlim’, [0.01 0.05], ‘xtick’, [0.01 0.02 0.03 0.04 0.05], ‘ylim’, [4 20], ‘ytick’, [4 8 12 16 20]);
grid on;
hold on;
% Create a meshgrid for plotting
[A, R] = meshgrid(a_interp, r_interp);
% Reshape the matrices to vectors for plotting
A_vector = reshape(A, [], 1);
R_vector = reshape(R, [], 1);
Re_cost_matrix_interp = reshape(cost_matrix_interp, [], 1);
% Find the global minimum in the interpolated cost matrix
[global_min_cost_interp, min_idx] = min(Re_cost_matrix_interp);
optimal_a_interp = A_vector(min_idx);
optimal_r_interp = R_vector(min_idx);
% Mark the minimum point
hold on;
surf_handle=plot3(optimal_a_interp, optimal_r_interp, global_min_cost_interp, ‘ro’, ‘MarkerSize’, 12, ‘MarkerFaceColor’, ‘r’);
view(3); % Set the viewing angle to 3D
% Bring the red point to the front
uistack(surf_handle, ‘top’); % Bring the red point to the front
hold off;
% Plot the 2D Contour Plot of the interpolated cost function
figure(2);
contourf(a_interp_grid, r_interp_grid, normalized_cost_matrix_interp, 20);
colorbar;
xlabel(‘alpha_{e} interp (m^{-1})’);
ylabel(‘R_{e} interp (mum)’);
title(‘2D Contour Plot of interpolated normalized CF’);
set(gca,’FontSize’, 12, ‘LineWidth’, 1, ‘FontWeight’, ‘normal’);
set(gca, ‘box’, ‘on’, ‘LineWidth’, 1, ‘FontName’, ‘Arial’, ‘FontSmoothing’, ‘on’);
set(gca, ‘xlim’, [0.01 0.05], ‘xtick’, [0.01 0.02 0.03 0.04 0.05], ‘ylim’, [4 20], ‘ytick’, [4 8 12 16 20]);
hold on;
plot(optimal_a_interp, optimal_r_interp, ‘ro’, ‘MarkerSize’, 12, ‘MarkerFaceColor’, ‘r’); % Mark the minimum point from interpolated grid search
% plot(optimal_a, optimal_r, ‘bo’, ‘MarkerSize’, 10, ‘LineWidth’, 2); % Mark the minimum point from original grid search
hold off;
% Plot the normalized cost values
figure(3);
scatter3(R_vector, A_vector, Re_cost_matrix_interp, ‘filled’);
xlabel(‘R_{e} interp (mum)’);
ylabel(‘alpha_{e} interp (m^{-1})’);
zlabel(‘Interpolated cost function’);
title(‘Normalized interpolated CF over alpha_{e} interp and R_{e} interp’);
set(gca, ‘color’, ‘w’, ‘FontSize’, 12, ‘LineWidth’, 1, ‘FontWeight’, ‘normal’);
set(gca, ‘box’, ‘on’, ‘FontName’, ‘Arial’, ‘FontSmoothing’, ‘on’);
set(gca, ‘ylim’, [0.01 0.05], ‘ytick’, [0.01 0.02 0.03 0.04 0.05], ‘xlim’, [4 20], ‘xtick’, [4 8 12 16 20]);
grid on;
hold on;
% Set the view angle
view(60, 40); % Adjust the view angles to see the plot clearly
% Mark the minimum point with a circle
surf_handle = plot3(optimal_r_interp, optimal_a_interp, global_min_cost_interp, ‘ro’, ‘MarkerSize’, 12, ‘MarkerFaceColor’, ‘r’);
% Bring the red point to the front
uistack(surf_handle, ‘top’); % Bring the red point to the front
hold off; cost_function, optimization MATLAB Answers — New Questions
probability distribution function from datra
Hi
i have a function Z(h) h1<h<h2 how i cant find a pdf (probability distribution finction ) function for Z
The variable h is unifrormly distributred in range [ h1 h1 ]
thank
GeorgeHi
i have a function Z(h) h1<h<h2 how i cant find a pdf (probability distribution finction ) function for Z
The variable h is unifrormly distributred in range [ h1 h1 ]
thank
George Hi
i have a function Z(h) h1<h<h2 how i cant find a pdf (probability distribution finction ) function for Z
The variable h is unifrormly distributred in range [ h1 h1 ]
thank
George pdf, random variable MATLAB Answers — New Questions
Input values that change continuously
In the process of co-simulating GT-SUITE and SIMULINK, I am creating a model that receives two input values of GT and outputs one output value in simulink. At this time, which block should I use if the two inputs are continuously changing?
Let me explain using the picture as an example. The values of Differential_Efficiency and FDR are continuously changing.In the process of co-simulating GT-SUITE and SIMULINK, I am creating a model that receives two input values of GT and outputs one output value in simulink. At this time, which block should I use if the two inputs are continuously changing?
Let me explain using the picture as an example. The values of Differential_Efficiency and FDR are continuously changing. In the process of co-simulating GT-SUITE and SIMULINK, I am creating a model that receives two input values of GT and outputs one output value in simulink. At this time, which block should I use if the two inputs are continuously changing?
Let me explain using the picture as an example. The values of Differential_Efficiency and FDR are continuously changing. co-simualtion, gt-suite MATLAB Answers — New Questions
Increase polygons for a stretch of road in Roadrunner
I have a question regarding the LOD settings in Roadrunner. Basically I’m trying to increase the numer of polygons, only for a single stretch of road, by reducing their size. Is it possible? Because otherwise I have to export and elaborate a file that is way much bigger.I have a question regarding the LOD settings in Roadrunner. Basically I’m trying to increase the numer of polygons, only for a single stretch of road, by reducing their size. Is it possible? Because otherwise I have to export and elaborate a file that is way much bigger. I have a question regarding the LOD settings in Roadrunner. Basically I’m trying to increase the numer of polygons, only for a single stretch of road, by reducing their size. Is it possible? Because otherwise I have to export and elaborate a file that is way much bigger. roadrunner, lod, polygons MATLAB Answers — New Questions
Which Polyspace version is compatible to run MISRA C 2020 STANDARD
Which Polyspace version is compatible to run MISRA C 2020 STANDARDWhich Polyspace version is compatible to run MISRA C 2020 STANDARD Which Polyspace version is compatible to run MISRA C 2020 STANDARD polyspace MATLAB Answers — New Questions
Fluid distribution in inclined rectangle
I’m working on a MATLAB code that simulates fluid distribution in an inclined rectangle. I’m encountering an issue with the fluid volume. It seems like the simulation is treating the rectangle as if it were still horizontal, limited by its original dimensions.
Here’s the specific problem:
At low fill levels, the fluid doesn’t lower past a certain point.
Similarly, at high fill levels, the fluid doesn’t fill the entire inclined rectangle, stopping again at the dashed blue line.
The maximum volume is 4.3L given the dimensions. I’ve attached the resulting plots of very low fill volume (0.01L) and high (4.2L).
How can I fix this?
Clarifications: the "dashed blue line" represents the non-inclined rectangle, the "brigth blue color" represents the fluid, the "black line" represents the tilted rectangle.I’m working on a MATLAB code that simulates fluid distribution in an inclined rectangle. I’m encountering an issue with the fluid volume. It seems like the simulation is treating the rectangle as if it were still horizontal, limited by its original dimensions.
Here’s the specific problem:
At low fill levels, the fluid doesn’t lower past a certain point.
Similarly, at high fill levels, the fluid doesn’t fill the entire inclined rectangle, stopping again at the dashed blue line.
The maximum volume is 4.3L given the dimensions. I’ve attached the resulting plots of very low fill volume (0.01L) and high (4.2L).
How can I fix this?
Clarifications: the "dashed blue line" represents the non-inclined rectangle, the "brigth blue color" represents the fluid, the "black line" represents the tilted rectangle. I’m working on a MATLAB code that simulates fluid distribution in an inclined rectangle. I’m encountering an issue with the fluid volume. It seems like the simulation is treating the rectangle as if it were still horizontal, limited by its original dimensions.
Here’s the specific problem:
At low fill levels, the fluid doesn’t lower past a certain point.
Similarly, at high fill levels, the fluid doesn’t fill the entire inclined rectangle, stopping again at the dashed blue line.
The maximum volume is 4.3L given the dimensions. I’ve attached the resulting plots of very low fill volume (0.01L) and high (4.2L).
How can I fix this?
Clarifications: the "dashed blue line" represents the non-inclined rectangle, the "brigth blue color" represents the fluid, the "black line" represents the tilted rectangle. matlab, error, matlab code MATLAB Answers — New Questions
How can I compute a graph with BER and EbN0 values
Now I have got images in the proper colour, I am wondering as to how plot a graph to show the Bit Error Rate to EbN0 in dB. I have found an example plot in another report but how can I plot this myself?
I know that semilogy is required for this but I am unsure where to start if anyone could point me to a MATLAB example or give any guidance on where to start with this?
Thanks in advanceNow I have got images in the proper colour, I am wondering as to how plot a graph to show the Bit Error Rate to EbN0 in dB. I have found an example plot in another report but how can I plot this myself?
I know that semilogy is required for this but I am unsure where to start if anyone could point me to a MATLAB example or give any guidance on where to start with this?
Thanks in advance Now I have got images in the proper colour, I am wondering as to how plot a graph to show the Bit Error Rate to EbN0 in dB. I have found an example plot in another report but how can I plot this myself?
I know that semilogy is required for this but I am unsure where to start if anyone could point me to a MATLAB example or give any guidance on where to start with this?
Thanks in advance awgn, ldpc, bit error rate, ebn0 MATLAB Answers — New Questions
Hi All. Just wondering why answer to (i) is not 4.9e+4. an why answer to (iii) is not (9x)/2 or 4.5 x. Many thanks. Brian
% (i) Find f(1.2) in the form ‘a x 10^n’ where a is correct to 1 decimal place
% (ii) Find x for which g(x) = 3.5
% (iii) Find g(f(x)) in simplest form
clear, clc
syms x
f = exp(9*x); g = log(sqrt(x));
% (i)
f_at_x = subs(f,x,1.2); % evaluates f(x = 1.2) as symbolic
f_at_x = double(f_at_x); % converts to double (real)
f_at_x = round(f_at_x,1) % ??? round to 1 decimal place
% (ii)
solve (g == 3.5, x)
% (iii)
g_f_x = (subs(g,x,f));
g_f_x = simplify(g_f_x)% (i) Find f(1.2) in the form ‘a x 10^n’ where a is correct to 1 decimal place
% (ii) Find x for which g(x) = 3.5
% (iii) Find g(f(x)) in simplest form
clear, clc
syms x
f = exp(9*x); g = log(sqrt(x));
% (i)
f_at_x = subs(f,x,1.2); % evaluates f(x = 1.2) as symbolic
f_at_x = double(f_at_x); % converts to double (real)
f_at_x = round(f_at_x,1) % ??? round to 1 decimal place
% (ii)
solve (g == 3.5, x)
% (iii)
g_f_x = (subs(g,x,f));
g_f_x = simplify(g_f_x) % (i) Find f(1.2) in the form ‘a x 10^n’ where a is correct to 1 decimal place
% (ii) Find x for which g(x) = 3.5
% (iii) Find g(f(x)) in simplest form
clear, clc
syms x
f = exp(9*x); g = log(sqrt(x));
% (i)
f_at_x = subs(f,x,1.2); % evaluates f(x = 1.2) as symbolic
f_at_x = double(f_at_x); % converts to double (real)
f_at_x = round(f_at_x,1) % ??? round to 1 decimal place
% (ii)
solve (g == 3.5, x)
% (iii)
g_f_x = (subs(g,x,f));
g_f_x = simplify(g_f_x) simplifying symbolic, rounding decimals MATLAB Answers — New Questions
Unrecognized “spharm” for spherical harmonics plot?
Hi, I get the following error when trying to plot
Unrecognized function or variable ‘spharm’.
Error in FTyD (line 35)
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
% Define the function f(t)
f = @(t) 139.85 + (15.8404 + 4.76022i) * exp(-1i * t) + (15.8404 – 4.76022i) * exp(1i * t) + …
(4.64917 – 3.3024i) * exp(-2i * t) + (4.64917 + 3.3024i) * exp(2i * t) + …
(7.42191 – 0.300123i) * exp(-3i * t) + (7.42191 + 0.300123i) * exp(3i * t) + …
(0.340877 – 2.54665i) * exp(-4i * t) + (0.340877 + 2.54665i) * exp(4i * t) + …
(7.72422 + 6.71332i) * exp(-5i * t) + (7.72422 – 6.71332i) * exp(5i * t) + …
(3.16511 – 9.14479i) * exp(-6i * t) + (3.16511 + 9.14479i) * exp(6i * t) + …
(3.31502 + 2.18874i) * exp(-7i * t) + (3.31502 – 2.18874i) * exp(7i * t) + …
(9.31827 + 6.94538i) * exp(-8i * t) + (9.31827 – 6.94538i) * exp(8i * t) + …
(5.87173 + 18.8341i) * exp(-9i * t) + (5.87173 – 18.8341i) * exp(9i * t) + …
(8.75949 + 14.7107i) * exp(-10i * t) + (8.75949 – 14.7107i) * exp(10i * t) + …
(19.2903 + 7.78329i) * exp(-11i * t) + (19.2903 – 7.78329i) * exp(11i * t) + …
(-3.39063 – 18.5502i) * exp(-12i * t) + (-3.39063 + 18.5502i) * exp(12i * t) + …
(3.58427 + 18.7438i) * exp(-13i * t) + (3.58427 – 18.7438i) * exp(13i * t) + …
(2.66129 + 20.0781i) * exp(-14i * t) + (2.66129 – 20.0781i) * exp(14i * t) + …
(-8.46335 – 9.96867i) * exp(-15i * t) + (-8.46335 + 9.96867i) * exp(15i * t) + …
(-8.50037 – 1.20377i) * exp(-16i * t) + (-8.50037 + 1.20377i) * exp(16i * t) + …
(-1.36102 – 16.9315i) * exp(-17i * t) + (-1.36102 + 16.9315i) * exp(17i * t) + …
(-5.78964 – 2.96094i) * exp(-18i * t) + (-5.78964 + 2.96094i) * exp(18i * t) + …
(2.14681 + 8.29635i) * exp(-19i * t) + (2.14681 – 8.29635i) * exp(19i * t) + …
(-3.91145 – 10.7712i) * exp(-20i * t) + (-3.91145 + 10.7712i) * exp(20i * t);
% Parameters
lmax = 10; % Maximum degree for spherical harmonics expansion
% Create grid in x and y
x = linspace(-10, 10, 100);
y = linspace(-10, 10, 100);
[X, Y] = meshgrid(x, y);
% Compute f(x,y)
Fxy = zeros(size(X));
for l = 0:lmax
for m = -l:l
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
integral_value = integral(@(t) f(t) .* conj(Ylm), -pi, pi); % Compute integral
Fxy = Fxy + integral_value * Ylm; % Accumulate to f(x,y)
end
end
% Plot
figure;
surf(X, Y, real(Fxy), ‘EdgeColor’, ‘none’);
xlabel(‘x’);
ylabel(‘y’);
zlabel(‘Re(f(x,y))’);
title(‘Method 3: Expansion in Spherical Harmonics’);
colorbar;
Cant figure out why…Hi, I get the following error when trying to plot
Unrecognized function or variable ‘spharm’.
Error in FTyD (line 35)
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
% Define the function f(t)
f = @(t) 139.85 + (15.8404 + 4.76022i) * exp(-1i * t) + (15.8404 – 4.76022i) * exp(1i * t) + …
(4.64917 – 3.3024i) * exp(-2i * t) + (4.64917 + 3.3024i) * exp(2i * t) + …
(7.42191 – 0.300123i) * exp(-3i * t) + (7.42191 + 0.300123i) * exp(3i * t) + …
(0.340877 – 2.54665i) * exp(-4i * t) + (0.340877 + 2.54665i) * exp(4i * t) + …
(7.72422 + 6.71332i) * exp(-5i * t) + (7.72422 – 6.71332i) * exp(5i * t) + …
(3.16511 – 9.14479i) * exp(-6i * t) + (3.16511 + 9.14479i) * exp(6i * t) + …
(3.31502 + 2.18874i) * exp(-7i * t) + (3.31502 – 2.18874i) * exp(7i * t) + …
(9.31827 + 6.94538i) * exp(-8i * t) + (9.31827 – 6.94538i) * exp(8i * t) + …
(5.87173 + 18.8341i) * exp(-9i * t) + (5.87173 – 18.8341i) * exp(9i * t) + …
(8.75949 + 14.7107i) * exp(-10i * t) + (8.75949 – 14.7107i) * exp(10i * t) + …
(19.2903 + 7.78329i) * exp(-11i * t) + (19.2903 – 7.78329i) * exp(11i * t) + …
(-3.39063 – 18.5502i) * exp(-12i * t) + (-3.39063 + 18.5502i) * exp(12i * t) + …
(3.58427 + 18.7438i) * exp(-13i * t) + (3.58427 – 18.7438i) * exp(13i * t) + …
(2.66129 + 20.0781i) * exp(-14i * t) + (2.66129 – 20.0781i) * exp(14i * t) + …
(-8.46335 – 9.96867i) * exp(-15i * t) + (-8.46335 + 9.96867i) * exp(15i * t) + …
(-8.50037 – 1.20377i) * exp(-16i * t) + (-8.50037 + 1.20377i) * exp(16i * t) + …
(-1.36102 – 16.9315i) * exp(-17i * t) + (-1.36102 + 16.9315i) * exp(17i * t) + …
(-5.78964 – 2.96094i) * exp(-18i * t) + (-5.78964 + 2.96094i) * exp(18i * t) + …
(2.14681 + 8.29635i) * exp(-19i * t) + (2.14681 – 8.29635i) * exp(19i * t) + …
(-3.91145 – 10.7712i) * exp(-20i * t) + (-3.91145 + 10.7712i) * exp(20i * t);
% Parameters
lmax = 10; % Maximum degree for spherical harmonics expansion
% Create grid in x and y
x = linspace(-10, 10, 100);
y = linspace(-10, 10, 100);
[X, Y] = meshgrid(x, y);
% Compute f(x,y)
Fxy = zeros(size(X));
for l = 0:lmax
for m = -l:l
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
integral_value = integral(@(t) f(t) .* conj(Ylm), -pi, pi); % Compute integral
Fxy = Fxy + integral_value * Ylm; % Accumulate to f(x,y)
end
end
% Plot
figure;
surf(X, Y, real(Fxy), ‘EdgeColor’, ‘none’);
xlabel(‘x’);
ylabel(‘y’);
zlabel(‘Re(f(x,y))’);
title(‘Method 3: Expansion in Spherical Harmonics’);
colorbar;
Cant figure out why… Hi, I get the following error when trying to plot
Unrecognized function or variable ‘spharm’.
Error in FTyD (line 35)
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
% Define the function f(t)
f = @(t) 139.85 + (15.8404 + 4.76022i) * exp(-1i * t) + (15.8404 – 4.76022i) * exp(1i * t) + …
(4.64917 – 3.3024i) * exp(-2i * t) + (4.64917 + 3.3024i) * exp(2i * t) + …
(7.42191 – 0.300123i) * exp(-3i * t) + (7.42191 + 0.300123i) * exp(3i * t) + …
(0.340877 – 2.54665i) * exp(-4i * t) + (0.340877 + 2.54665i) * exp(4i * t) + …
(7.72422 + 6.71332i) * exp(-5i * t) + (7.72422 – 6.71332i) * exp(5i * t) + …
(3.16511 – 9.14479i) * exp(-6i * t) + (3.16511 + 9.14479i) * exp(6i * t) + …
(3.31502 + 2.18874i) * exp(-7i * t) + (3.31502 – 2.18874i) * exp(7i * t) + …
(9.31827 + 6.94538i) * exp(-8i * t) + (9.31827 – 6.94538i) * exp(8i * t) + …
(5.87173 + 18.8341i) * exp(-9i * t) + (5.87173 – 18.8341i) * exp(9i * t) + …
(8.75949 + 14.7107i) * exp(-10i * t) + (8.75949 – 14.7107i) * exp(10i * t) + …
(19.2903 + 7.78329i) * exp(-11i * t) + (19.2903 – 7.78329i) * exp(11i * t) + …
(-3.39063 – 18.5502i) * exp(-12i * t) + (-3.39063 + 18.5502i) * exp(12i * t) + …
(3.58427 + 18.7438i) * exp(-13i * t) + (3.58427 – 18.7438i) * exp(13i * t) + …
(2.66129 + 20.0781i) * exp(-14i * t) + (2.66129 – 20.0781i) * exp(14i * t) + …
(-8.46335 – 9.96867i) * exp(-15i * t) + (-8.46335 + 9.96867i) * exp(15i * t) + …
(-8.50037 – 1.20377i) * exp(-16i * t) + (-8.50037 + 1.20377i) * exp(16i * t) + …
(-1.36102 – 16.9315i) * exp(-17i * t) + (-1.36102 + 16.9315i) * exp(17i * t) + …
(-5.78964 – 2.96094i) * exp(-18i * t) + (-5.78964 + 2.96094i) * exp(18i * t) + …
(2.14681 + 8.29635i) * exp(-19i * t) + (2.14681 – 8.29635i) * exp(19i * t) + …
(-3.91145 – 10.7712i) * exp(-20i * t) + (-3.91145 + 10.7712i) * exp(20i * t);
% Parameters
lmax = 10; % Maximum degree for spherical harmonics expansion
% Create grid in x and y
x = linspace(-10, 10, 100);
y = linspace(-10, 10, 100);
[X, Y] = meshgrid(x, y);
% Compute f(x,y)
Fxy = zeros(size(X));
for l = 0:lmax
for m = -l:l
Ylm = spharm(l, m, Y, X); % Evaluate spherical harmonic Y_lm(x,y)
integral_value = integral(@(t) f(t) .* conj(Ylm), -pi, pi); % Compute integral
Fxy = Fxy + integral_value * Ylm; % Accumulate to f(x,y)
end
end
% Plot
figure;
surf(X, Y, real(Fxy), ‘EdgeColor’, ‘none’);
xlabel(‘x’);
ylabel(‘y’);
zlabel(‘Re(f(x,y))’);
title(‘Method 3: Expansion in Spherical Harmonics’);
colorbar;
Cant figure out why… 3d plots, spherical, harmonics MATLAB Answers — New Questions
How can I use HDL Coder with an unsupported or custom FPGA board?
MathWorks provides integrated solutions for popular FPGA evaluation boards listed here:Hardware support from HDL Coder
However, the evaluation board that I use is not supported, or I created a custom board for moving to production. How can I use HDL Coder with an unsupported or custom FPGA board?MathWorks provides integrated solutions for popular FPGA evaluation boards listed here:Hardware support from HDL Coder
However, the evaluation board that I use is not supported, or I created a custom board for moving to production. How can I use HDL Coder with an unsupported or custom FPGA board? MathWorks provides integrated solutions for popular FPGA evaluation boards listed here:Hardware support from HDL Coder
However, the evaluation board that I use is not supported, or I created a custom board for moving to production. How can I use HDL Coder with an unsupported or custom FPGA board? hdl, coder, unsupported, target, platform, device, board MATLAB Answers — New Questions
Why do I get a warning that the code coverage result is empty because the file is invalid?
I’m trying to add code coverage to my unit test suite. There is one .mlapp file that gives this warning:
Warning: Coverage result is empty for /MyPath/myApp.mlapp because the file is invalid.
How can I find out what is wrong with the file? The app works, so I don’t know why it would be "invalid." Note: a blank .mlapp file does not give the same warning.I’m trying to add code coverage to my unit test suite. There is one .mlapp file that gives this warning:
Warning: Coverage result is empty for /MyPath/myApp.mlapp because the file is invalid.
How can I find out what is wrong with the file? The app works, so I don’t know why it would be "invalid." Note: a blank .mlapp file does not give the same warning. I’m trying to add code coverage to my unit test suite. There is one .mlapp file that gives this warning:
Warning: Coverage result is empty for /MyPath/myApp.mlapp because the file is invalid.
How can I find out what is wrong with the file? The app works, so I don’t know why it would be "invalid." Note: a blank .mlapp file does not give the same warning. code coverage MATLAB Answers — New Questions
Error Message “‘This package uses the Matlab command xlsread to read from Excel files….” Matlab 6/Matlab 7
Dear all,
when I’m running the file DSGEFig1.m a window pops up, asking for "Specify Excel: Enter the name of the Excel input file". Now the problem is that when I enter the excel file and click OK, I get the following error message:
‘This package uses the Matlab command xlsread to read from Excel files.’,…
‘This command appeared for the first time in Matlab 6. Your version of Matlab is older than version 6.’,…
‘You must modify the file DSGEReadExcel to read in data etc in some other way. Or upgrade Matlab …’
I use the Matlab version 2023b.
I’ve read a previous post that one can try
which -all xlsread
and check for third party toolboxes and support packages. However, when I enter this code line, I get
/Applications/MATLAB_R2023b.app/toolbox/matlab/iofun/xlsread.m
As I see it, third party toolboxes and support packages are not the problem in my case.
I tried to change the code in DSGEReadExcel from xlsread to readtable and readmatrix but I still get the same error message.
Can someone help me and tell me, how I can solve the problem?
Many thanks for your help!Dear all,
when I’m running the file DSGEFig1.m a window pops up, asking for "Specify Excel: Enter the name of the Excel input file". Now the problem is that when I enter the excel file and click OK, I get the following error message:
‘This package uses the Matlab command xlsread to read from Excel files.’,…
‘This command appeared for the first time in Matlab 6. Your version of Matlab is older than version 6.’,…
‘You must modify the file DSGEReadExcel to read in data etc in some other way. Or upgrade Matlab …’
I use the Matlab version 2023b.
I’ve read a previous post that one can try
which -all xlsread
and check for third party toolboxes and support packages. However, when I enter this code line, I get
/Applications/MATLAB_R2023b.app/toolbox/matlab/iofun/xlsread.m
As I see it, third party toolboxes and support packages are not the problem in my case.
I tried to change the code in DSGEReadExcel from xlsread to readtable and readmatrix but I still get the same error message.
Can someone help me and tell me, how I can solve the problem?
Many thanks for your help! Dear all,
when I’m running the file DSGEFig1.m a window pops up, asking for "Specify Excel: Enter the name of the Excel input file". Now the problem is that when I enter the excel file and click OK, I get the following error message:
‘This package uses the Matlab command xlsread to read from Excel files.’,…
‘This command appeared for the first time in Matlab 6. Your version of Matlab is older than version 6.’,…
‘You must modify the file DSGEReadExcel to read in data etc in some other way. Or upgrade Matlab …’
I use the Matlab version 2023b.
I’ve read a previous post that one can try
which -all xlsread
and check for third party toolboxes and support packages. However, when I enter this code line, I get
/Applications/MATLAB_R2023b.app/toolbox/matlab/iofun/xlsread.m
As I see it, third party toolboxes and support packages are not the problem in my case.
I tried to change the code in DSGEReadExcel from xlsread to readtable and readmatrix but I still get the same error message.
Can someone help me and tell me, how I can solve the problem?
Many thanks for your help! matlab6, matlab7, excel, xlsread MATLAB Answers — New Questions
Which license should I choose for a single server with multiple users
I’m the admin of a server and I need to obtain a MATLAB license. Some details:
Single server
We are using SLURM to balance the workload
There are about 20 users in total
There are about ~5 users that need MATLAB for now. This might be more in the future
Required toolboxes (at least for now): Image Processing, Signal Processing, Optimization
I’ve read online about different options (e.g. network license, parallel server, individual license vs designated computer license), but I’m still confused as to what should I get for this case.I’m the admin of a server and I need to obtain a MATLAB license. Some details:
Single server
We are using SLURM to balance the workload
There are about 20 users in total
There are about ~5 users that need MATLAB for now. This might be more in the future
Required toolboxes (at least for now): Image Processing, Signal Processing, Optimization
I’ve read online about different options (e.g. network license, parallel server, individual license vs designated computer license), but I’m still confused as to what should I get for this case. I’m the admin of a server and I need to obtain a MATLAB license. Some details:
Single server
We are using SLURM to balance the workload
There are about 20 users in total
There are about ~5 users that need MATLAB for now. This might be more in the future
Required toolboxes (at least for now): Image Processing, Signal Processing, Optimization
I’ve read online about different options (e.g. network license, parallel server, individual license vs designated computer license), but I’m still confused as to what should I get for this case. licenses, matlab, server MATLAB Answers — New Questions
How to edit the red “+” marks on the Nyquist plot
Is there a way to change the thickness and color of the red + marks that appear when drawing a Nyquist diagram?Is there a way to change the thickness and color of the red + marks that appear when drawing a Nyquist diagram? Is there a way to change the thickness and color of the red + marks that appear when drawing a Nyquist diagram? nyquist, ナイキスト線図 MATLAB Answers — New Questions