Category: Matlab
Category Archives: Matlab
Calculation with three dimensional matrices
I want to calculate a vector , with each element defined as follows
, where is the set of dimensional vector, and is also the set of dimensional vector, is a constant. The superscript is denoted as the transpose operation.
In my matlab code, is stored as a three dimensional matrix , its dimension is (where ).
is also stored as a three dimensional matrix , its dimension is (where ). is a scalar.
I know i can use multiple for loop to calculate this vector , but it is too inefficient. Is there any some fast way to calculate it, maybe use three-dimensional matrix calculation method?I want to calculate a vector , with each element defined as follows
, where is the set of dimensional vector, and is also the set of dimensional vector, is a constant. The superscript is denoted as the transpose operation.
In my matlab code, is stored as a three dimensional matrix , its dimension is (where ).
is also stored as a three dimensional matrix , its dimension is (where ). is a scalar.
I know i can use multiple for loop to calculate this vector , but it is too inefficient. Is there any some fast way to calculate it, maybe use three-dimensional matrix calculation method? I want to calculate a vector , with each element defined as follows
, where is the set of dimensional vector, and is also the set of dimensional vector, is a constant. The superscript is denoted as the transpose operation.
In my matlab code, is stored as a three dimensional matrix , its dimension is (where ).
is also stored as a three dimensional matrix , its dimension is (where ). is a scalar.
I know i can use multiple for loop to calculate this vector , but it is too inefficient. Is there any some fast way to calculate it, maybe use three-dimensional matrix calculation method? matrix manipulation MATLAB Answers — New Questions
machine learning and artificial intelligence
hello every one
i need help with my artificial intelligence Project .
i am a Power-Electronics student and i have a project in which i have to use Artificial intelligence But i have no idea about this issue. i want to learn about
artificial Inteligence and machine learning and also how to implement it in Matlab .
could you Please introduce me some sources Or tutorial which is usefull for me ??hello every one
i need help with my artificial intelligence Project .
i am a Power-Electronics student and i have a project in which i have to use Artificial intelligence But i have no idea about this issue. i want to learn about
artificial Inteligence and machine learning and also how to implement it in Matlab .
could you Please introduce me some sources Or tutorial which is usefull for me ?? hello every one
i need help with my artificial intelligence Project .
i am a Power-Electronics student and i have a project in which i have to use Artificial intelligence But i have no idea about this issue. i want to learn about
artificial Inteligence and machine learning and also how to implement it in Matlab .
could you Please introduce me some sources Or tutorial which is usefull for me ?? artificial intelligence-machine learning-neural network-matlab projects MATLAB Answers — New Questions
Does gather() clear memory
I am running in to memory limits on my GPUs. I know I can reset(gpuDevice) to clear all memory on the device, however, I would like to move arrays one at a time from GPU memory to memory and then clear the orginal GPU version. Does gather() also clear the GPU memory after copying/moving to memory?
If not, what would be the best way to achieve this?I am running in to memory limits on my GPUs. I know I can reset(gpuDevice) to clear all memory on the device, however, I would like to move arrays one at a time from GPU memory to memory and then clear the orginal GPU version. Does gather() also clear the GPU memory after copying/moving to memory?
If not, what would be the best way to achieve this? I am running in to memory limits on my GPUs. I know I can reset(gpuDevice) to clear all memory on the device, however, I would like to move arrays one at a time from GPU memory to memory and then clear the orginal GPU version. Does gather() also clear the GPU memory after copying/moving to memory?
If not, what would be the best way to achieve this? gather, gpu, memory MATLAB Answers — New Questions
regarding fake currency detection matlab code…it is showing “real” even if i upload fake image,please rectify my code
% Step 1: Load the Image
[FILENAME, PATHNAME] = uigetfile(‘*.jpg’, ‘Select an Image’);
if isequal(FILENAME, 0)
disp(‘User canceled the image selection.’);
return;
end
FilePath = strcat(PATHNAME, FILENAME);
disp(‘Selected Image Location:’);
disp(FilePath);
% Step 2: Read and Resize the Image
DataArray = imread(FilePath); % Read the image
DataArray = imresize(DataArray, [300, 650]); % Resize image to a standard size
figure, imshow(DataArray); % Display image
title(‘Original Image’);
% Step 3: Convert to Grayscale
Igray = rgb2gray(DataArray); % Convert to grayscale
figure, imshow(Igray); % Display grayscale image
title(‘Grayscale Image’);
% Step 4: Noise Removal using Median Filter
Igray = medfilt2(Igray); % Apply median filter to remove noise
figure, imshow(Igray);
title(‘Denoised Grayscale Image’);
% Step 5: Edge Detection (using Sobel operator)
edges = edge(Igray, ‘Sobel’); % Detect edges using Sobel method
figure, imshow(edges);
title(‘Edge Detection’);
% Step 6: Feature Extraction – Texture Features using GLCM
% Calculate the Gray Level Co-occurrence Matrix (GLCM)
glcm = graycomatrix(Igray, ‘Offset’, [0 1; -1 1; -1 0; -1 -1]);
stats = graycoprops(glcm, {‘Contrast’, ‘Correlation’, ‘Energy’, ‘Homogeneity’});
% Extract features from GLCM
Contrast = stats.Contrast;
Correlation = stats.Correlation;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
% Step 7: Feature Extraction – Shape Features using Regionprops
props = regionprops(edges, ‘Area’, ‘Eccentricity’, ‘Solidity’);
Area = [props.Area]; % Extract Area
Eccentricity = [props.Eccentricity]; % Extract Eccentricity
Solidity = [props.Solidity]; % Extract Solidity
% Step 8: Create Feature Vector
Features = [mean(Contrast), mean(Correlation), mean(Energy), mean(Homogeneity), mean(Area), mean(Eccentricity), mean(Solidity)];
disp(‘Extracted Features:’);
disp(Features);
% Step 9: Prepare Training Data (for SVM)
% Example of real and fake currency training data (manually labeled)
% In real projects, you’d use a dataset with images of real and fake currency
Real_Data = [
% Example feature values for real currency
0.1, 0.9, 0.8, 0.7, 2500, 0.6, 0.95; % Example feature values for real currency
% Add more real currency data points
];
Fake_Data = [
% Example feature values for fake currency
0.5, 0.4, 0.2, 0.3, 2000, 0.8, 0.3; % Example feature values for fake currency
% Add more fake currency data points
];
% Step 10: Labels for Training Data
% 1 for real currency, 0 for fake currency
Real_Labels = ones(size(Real_Data, 1), 1);
Fake_Labels = zeros(size(Fake_Data, 1), 1);
% Combine real and fake data
Train_Data = [Real_Data; Fake_Data];
Train_Labels = [Real_Labels; Fake_Labels];
% Step 11: Train an SVM Classifier
svmModel = fitcsvm(Train_Data, Train_Labels, ‘KernelFunction’, ‘rbf’, ‘Standardize’, true);
% Step 12: Test the classifier with the current image features
[Label, Score] = predict(svmModel, Features); % Classify using the SVM model
% Step 13: Display the result
if Label == 1
msgbox(‘Currency Type: Real’);
else
msgbox(‘Currency Type: Fake’);
end
% Step 14: Display Final Image with Result
figure, imshow(DataArray);
if Label == 1
title(‘Detected: Real Currency’);
else
title(‘Detected: Fake Currency’);
end% Step 1: Load the Image
[FILENAME, PATHNAME] = uigetfile(‘*.jpg’, ‘Select an Image’);
if isequal(FILENAME, 0)
disp(‘User canceled the image selection.’);
return;
end
FilePath = strcat(PATHNAME, FILENAME);
disp(‘Selected Image Location:’);
disp(FilePath);
% Step 2: Read and Resize the Image
DataArray = imread(FilePath); % Read the image
DataArray = imresize(DataArray, [300, 650]); % Resize image to a standard size
figure, imshow(DataArray); % Display image
title(‘Original Image’);
% Step 3: Convert to Grayscale
Igray = rgb2gray(DataArray); % Convert to grayscale
figure, imshow(Igray); % Display grayscale image
title(‘Grayscale Image’);
% Step 4: Noise Removal using Median Filter
Igray = medfilt2(Igray); % Apply median filter to remove noise
figure, imshow(Igray);
title(‘Denoised Grayscale Image’);
% Step 5: Edge Detection (using Sobel operator)
edges = edge(Igray, ‘Sobel’); % Detect edges using Sobel method
figure, imshow(edges);
title(‘Edge Detection’);
% Step 6: Feature Extraction – Texture Features using GLCM
% Calculate the Gray Level Co-occurrence Matrix (GLCM)
glcm = graycomatrix(Igray, ‘Offset’, [0 1; -1 1; -1 0; -1 -1]);
stats = graycoprops(glcm, {‘Contrast’, ‘Correlation’, ‘Energy’, ‘Homogeneity’});
% Extract features from GLCM
Contrast = stats.Contrast;
Correlation = stats.Correlation;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
% Step 7: Feature Extraction – Shape Features using Regionprops
props = regionprops(edges, ‘Area’, ‘Eccentricity’, ‘Solidity’);
Area = [props.Area]; % Extract Area
Eccentricity = [props.Eccentricity]; % Extract Eccentricity
Solidity = [props.Solidity]; % Extract Solidity
% Step 8: Create Feature Vector
Features = [mean(Contrast), mean(Correlation), mean(Energy), mean(Homogeneity), mean(Area), mean(Eccentricity), mean(Solidity)];
disp(‘Extracted Features:’);
disp(Features);
% Step 9: Prepare Training Data (for SVM)
% Example of real and fake currency training data (manually labeled)
% In real projects, you’d use a dataset with images of real and fake currency
Real_Data = [
% Example feature values for real currency
0.1, 0.9, 0.8, 0.7, 2500, 0.6, 0.95; % Example feature values for real currency
% Add more real currency data points
];
Fake_Data = [
% Example feature values for fake currency
0.5, 0.4, 0.2, 0.3, 2000, 0.8, 0.3; % Example feature values for fake currency
% Add more fake currency data points
];
% Step 10: Labels for Training Data
% 1 for real currency, 0 for fake currency
Real_Labels = ones(size(Real_Data, 1), 1);
Fake_Labels = zeros(size(Fake_Data, 1), 1);
% Combine real and fake data
Train_Data = [Real_Data; Fake_Data];
Train_Labels = [Real_Labels; Fake_Labels];
% Step 11: Train an SVM Classifier
svmModel = fitcsvm(Train_Data, Train_Labels, ‘KernelFunction’, ‘rbf’, ‘Standardize’, true);
% Step 12: Test the classifier with the current image features
[Label, Score] = predict(svmModel, Features); % Classify using the SVM model
% Step 13: Display the result
if Label == 1
msgbox(‘Currency Type: Real’);
else
msgbox(‘Currency Type: Fake’);
end
% Step 14: Display Final Image with Result
figure, imshow(DataArray);
if Label == 1
title(‘Detected: Real Currency’);
else
title(‘Detected: Fake Currency’);
end % Step 1: Load the Image
[FILENAME, PATHNAME] = uigetfile(‘*.jpg’, ‘Select an Image’);
if isequal(FILENAME, 0)
disp(‘User canceled the image selection.’);
return;
end
FilePath = strcat(PATHNAME, FILENAME);
disp(‘Selected Image Location:’);
disp(FilePath);
% Step 2: Read and Resize the Image
DataArray = imread(FilePath); % Read the image
DataArray = imresize(DataArray, [300, 650]); % Resize image to a standard size
figure, imshow(DataArray); % Display image
title(‘Original Image’);
% Step 3: Convert to Grayscale
Igray = rgb2gray(DataArray); % Convert to grayscale
figure, imshow(Igray); % Display grayscale image
title(‘Grayscale Image’);
% Step 4: Noise Removal using Median Filter
Igray = medfilt2(Igray); % Apply median filter to remove noise
figure, imshow(Igray);
title(‘Denoised Grayscale Image’);
% Step 5: Edge Detection (using Sobel operator)
edges = edge(Igray, ‘Sobel’); % Detect edges using Sobel method
figure, imshow(edges);
title(‘Edge Detection’);
% Step 6: Feature Extraction – Texture Features using GLCM
% Calculate the Gray Level Co-occurrence Matrix (GLCM)
glcm = graycomatrix(Igray, ‘Offset’, [0 1; -1 1; -1 0; -1 -1]);
stats = graycoprops(glcm, {‘Contrast’, ‘Correlation’, ‘Energy’, ‘Homogeneity’});
% Extract features from GLCM
Contrast = stats.Contrast;
Correlation = stats.Correlation;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
% Step 7: Feature Extraction – Shape Features using Regionprops
props = regionprops(edges, ‘Area’, ‘Eccentricity’, ‘Solidity’);
Area = [props.Area]; % Extract Area
Eccentricity = [props.Eccentricity]; % Extract Eccentricity
Solidity = [props.Solidity]; % Extract Solidity
% Step 8: Create Feature Vector
Features = [mean(Contrast), mean(Correlation), mean(Energy), mean(Homogeneity), mean(Area), mean(Eccentricity), mean(Solidity)];
disp(‘Extracted Features:’);
disp(Features);
% Step 9: Prepare Training Data (for SVM)
% Example of real and fake currency training data (manually labeled)
% In real projects, you’d use a dataset with images of real and fake currency
Real_Data = [
% Example feature values for real currency
0.1, 0.9, 0.8, 0.7, 2500, 0.6, 0.95; % Example feature values for real currency
% Add more real currency data points
];
Fake_Data = [
% Example feature values for fake currency
0.5, 0.4, 0.2, 0.3, 2000, 0.8, 0.3; % Example feature values for fake currency
% Add more fake currency data points
];
% Step 10: Labels for Training Data
% 1 for real currency, 0 for fake currency
Real_Labels = ones(size(Real_Data, 1), 1);
Fake_Labels = zeros(size(Fake_Data, 1), 1);
% Combine real and fake data
Train_Data = [Real_Data; Fake_Data];
Train_Labels = [Real_Labels; Fake_Labels];
% Step 11: Train an SVM Classifier
svmModel = fitcsvm(Train_Data, Train_Labels, ‘KernelFunction’, ‘rbf’, ‘Standardize’, true);
% Step 12: Test the classifier with the current image features
[Label, Score] = predict(svmModel, Features); % Classify using the SVM model
% Step 13: Display the result
if Label == 1
msgbox(‘Currency Type: Real’);
else
msgbox(‘Currency Type: Fake’);
end
% Step 14: Display Final Image with Result
figure, imshow(DataArray);
if Label == 1
title(‘Detected: Real Currency’);
else
title(‘Detected: Fake Currency’);
end image processing MATLAB Answers — New Questions
Issue with parameter estimation in Battery(Table-based) block
Hi,
I am in between estimating the parameter of 1RC battery model(using battery(table based) block). I have set initial parameters for V0,R0,R1 and Tau1. Since i have experimental pulse discharge data values of 6190 seconds, my paramters for estimations are also column vector of size 6190X1. i am using parameter estimation toolbox for optimization and least square algorithm. in new experiment tab, i have set pulse discharge data values as "Output" variable. in parameter, i set V0,R0,R1 and Tau1 with initials guess of all paramters. when running the estimation, the app shows its estimating (at bottom), and the model is running the iterations. but at the end, the the estimation output is "Initial point is local minimum" and iteration=0 and F-Count=513. also the estimated parameters plot is empty. I am unable to guess what is happening?? please help. ThanksHi,
I am in between estimating the parameter of 1RC battery model(using battery(table based) block). I have set initial parameters for V0,R0,R1 and Tau1. Since i have experimental pulse discharge data values of 6190 seconds, my paramters for estimations are also column vector of size 6190X1. i am using parameter estimation toolbox for optimization and least square algorithm. in new experiment tab, i have set pulse discharge data values as "Output" variable. in parameter, i set V0,R0,R1 and Tau1 with initials guess of all paramters. when running the estimation, the app shows its estimating (at bottom), and the model is running the iterations. but at the end, the the estimation output is "Initial point is local minimum" and iteration=0 and F-Count=513. also the estimated parameters plot is empty. I am unable to guess what is happening?? please help. Thanks Hi,
I am in between estimating the parameter of 1RC battery model(using battery(table based) block). I have set initial parameters for V0,R0,R1 and Tau1. Since i have experimental pulse discharge data values of 6190 seconds, my paramters for estimations are also column vector of size 6190X1. i am using parameter estimation toolbox for optimization and least square algorithm. in new experiment tab, i have set pulse discharge data values as "Output" variable. in parameter, i set V0,R0,R1 and Tau1 with initials guess of all paramters. when running the estimation, the app shows its estimating (at bottom), and the model is running the iterations. but at the end, the the estimation output is "Initial point is local minimum" and iteration=0 and F-Count=513. also the estimated parameters plot is empty. I am unable to guess what is happening?? please help. Thanks parameter estimation, simulink, optimization MATLAB Answers — New Questions
How to clear serial port buffers from matlab to arduino?
Hi there, I tried to use ‘flush’ to clear the serial buffer sent from MATLAB to Arduino, but I can’t make it. Here is a simple code in MATLAB:
device = serialport("/dev/cu.usbmodem2101",9600);
write(device, 1:5, "uint8");
The device.NumBytesAvailable = 0, and device.NumBytesWritten = 5, and after I run this:
flush(device);
the device.NumBytesWritten is still 5.
I’ve tried different MATLAB versions (2022b,and 2019b, and tried to clear this in arduino, but neither works.
Please help me. I don’t know what’s going wrong and I’ve been stuck in this for several days. Thanks.Hi there, I tried to use ‘flush’ to clear the serial buffer sent from MATLAB to Arduino, but I can’t make it. Here is a simple code in MATLAB:
device = serialport("/dev/cu.usbmodem2101",9600);
write(device, 1:5, "uint8");
The device.NumBytesAvailable = 0, and device.NumBytesWritten = 5, and after I run this:
flush(device);
the device.NumBytesWritten is still 5.
I’ve tried different MATLAB versions (2022b,and 2019b, and tried to clear this in arduino, but neither works.
Please help me. I don’t know what’s going wrong and I’ve been stuck in this for several days. Thanks. Hi there, I tried to use ‘flush’ to clear the serial buffer sent from MATLAB to Arduino, but I can’t make it. Here is a simple code in MATLAB:
device = serialport("/dev/cu.usbmodem2101",9600);
write(device, 1:5, "uint8");
The device.NumBytesAvailable = 0, and device.NumBytesWritten = 5, and after I run this:
flush(device);
the device.NumBytesWritten is still 5.
I’ve tried different MATLAB versions (2022b,and 2019b, and tried to clear this in arduino, but neither works.
Please help me. I don’t know what’s going wrong and I’ve been stuck in this for several days. Thanks. arduino, matlab, buffer, clear, flush MATLAB Answers — New Questions
I want to replace the hyphens with en dashes in a plot axes.
Dear all
I need help with replacing the hyphens in the y-axis with en dashes in a plot. In other words, I want to increase the length of the negative sing in the plot axis.
Thanks
AzizDear all
I need help with replacing the hyphens in the y-axis with en dashes in a plot. In other words, I want to increase the length of the negative sing in the plot axis.
Thanks
Aziz Dear all
I need help with replacing the hyphens in the y-axis with en dashes in a plot. In other words, I want to increase the length of the negative sing in the plot axis.
Thanks
Aziz replace the hyphens with en dashes MATLAB Answers — New Questions
First order partial differential equations system – Numerical solution
Hello everyone!
I would like to solve a first order partial differential equations (2 coupled equations) system numerically. I just want to make sure that my thoughts are correct.
So firstly, I will start by doing a discretization to each of the two equations and then I will use ode15s to solve the ordinary differential equations that I got from the first step. Am I right? Which method of discretization do you recommend me to use?
Note: My equations are similar to the linear advection equation but with a source term.
Thank you very much.
MalakHello everyone!
I would like to solve a first order partial differential equations (2 coupled equations) system numerically. I just want to make sure that my thoughts are correct.
So firstly, I will start by doing a discretization to each of the two equations and then I will use ode15s to solve the ordinary differential equations that I got from the first step. Am I right? Which method of discretization do you recommend me to use?
Note: My equations are similar to the linear advection equation but with a source term.
Thank you very much.
Malak Hello everyone!
I would like to solve a first order partial differential equations (2 coupled equations) system numerically. I just want to make sure that my thoughts are correct.
So firstly, I will start by doing a discretization to each of the two equations and then I will use ode15s to solve the ordinary differential equations that I got from the first step. Am I right? Which method of discretization do you recommend me to use?
Note: My equations are similar to the linear advection equation but with a source term.
Thank you very much.
Malak partial differential equations, first order, hyperbolic, discretization, pdepe MATLAB Answers — New Questions
I want to measure the line voltages in a three phase system, can I connect the voltage measurement between the two phases? Does it mean short circuiting the two phases?
I want to know whether voltage measurement short circuits or not when connected between two phases to measure line voltage.I want to know whether voltage measurement short circuits or not when connected between two phases to measure line voltage. I want to know whether voltage measurement short circuits or not when connected between two phases to measure line voltage. voltage measurement MATLAB Answers — New Questions
about ‘matlab function’ using refprom to get properties of methane
Hi there,
I want to link REFPROP with Simulink for methane. The pressure and temperature of the working fluid change. I want to import the fluid properties to Simulink, considering the changing pressure and temperature. Is it possible, and how can I do that?Hi there,
I want to link REFPROP with Simulink for methane. The pressure and temperature of the working fluid change. I want to import the fluid properties to Simulink, considering the changing pressure and temperature. Is it possible, and how can I do that? Hi there,
I want to link REFPROP with Simulink for methane. The pressure and temperature of the working fluid change. I want to import the fluid properties to Simulink, considering the changing pressure and temperature. Is it possible, and how can I do that? simulink, simulink refpropm MATLAB Answers — New Questions
My previous question was closed by John D’Errico – fair enough – but I am not a student doing homework but 69 years old – and in the past you helped me to solve 7 polynomial
s*x+i = (x^2*v^2/w^2+v^2)^(1/2) wanted that solved for xs*x+i = (x^2*v^2/w^2+v^2)^(1/2) wanted that solved for x s*x+i = (x^2*v^2/w^2+v^2)^(1/2) wanted that solved for x qualified questions MATLAB Answers — New Questions
Which matlab will i be able to use in my pc?
the specs of my pc are windows 7 32 bit operating system
processor : pentium(R) dual core cpu E5700@ 3.00Ghzthe specs of my pc are windows 7 32 bit operating system
processor : pentium(R) dual core cpu E5700@ 3.00Ghz the specs of my pc are windows 7 32 bit operating system
processor : pentium(R) dual core cpu E5700@ 3.00Ghz release MATLAB Answers — New Questions
Axis ticks and colorbar labels in bold (heatmap)?
I created a heatmap and I’ve got my axis labels in bold for better visibility. I had to use this ‘bf thing to be able to do that, because, apparently, the normal way of:
h = heatmap(X, Y, C, ‘FontName’, ‘Times New Roman’, ‘FontSize’, 13, ‘FontWeight’, ‘bold’);
doesn’t work with heatmaps.
Now, I’d like to have the axis ticks and the colorbar labels in bold as well. Is that a way to do so in matlab? I couldn’t find a solution for that by myself.I created a heatmap and I’ve got my axis labels in bold for better visibility. I had to use this ‘bf thing to be able to do that, because, apparently, the normal way of:
h = heatmap(X, Y, C, ‘FontName’, ‘Times New Roman’, ‘FontSize’, 13, ‘FontWeight’, ‘bold’);
doesn’t work with heatmaps.
Now, I’d like to have the axis ticks and the colorbar labels in bold as well. Is that a way to do so in matlab? I couldn’t find a solution for that by myself. I created a heatmap and I’ve got my axis labels in bold for better visibility. I had to use this ‘bf thing to be able to do that, because, apparently, the normal way of:
h = heatmap(X, Y, C, ‘FontName’, ‘Times New Roman’, ‘FontSize’, 13, ‘FontWeight’, ‘bold’);
doesn’t work with heatmaps.
Now, I’d like to have the axis ticks and the colorbar labels in bold as well. Is that a way to do so in matlab? I couldn’t find a solution for that by myself. heatmap, axis ticks, colorbar, bold MATLAB Answers — New Questions
I am having difficulty in modeling 1D SOFC stack model
Hello ,
I am trying to develop a 1D SOFC model based on FDM or FVM based discretization. but SOFC stack has many sub-models and all are connected in real time how would i start ? what would be my modeling strategy ( scriipt or Simulink ) and how i break my task?
such as electrical sub model , chemcial and electrochemical sub model , mass conseration , and species conservation ?Hello ,
I am trying to develop a 1D SOFC model based on FDM or FVM based discretization. but SOFC stack has many sub-models and all are connected in real time how would i start ? what would be my modeling strategy ( scriipt or Simulink ) and how i break my task?
such as electrical sub model , chemcial and electrochemical sub model , mass conseration , and species conservation ? Hello ,
I am trying to develop a 1D SOFC model based on FDM or FVM based discretization. but SOFC stack has many sub-models and all are connected in real time how would i start ? what would be my modeling strategy ( scriipt or Simulink ) and how i break my task?
such as electrical sub model , chemcial and electrochemical sub model , mass conseration , and species conservation ? sofc, sofc model MATLAB Answers — New Questions
Does enu2ecefv make any assumptions about the ellipsoid?
From my understanding of the formula, the parameters for the ellipsoid (semimajor axes, flattening, etc.) are not taken into account at all in the calculation. Does this calculation assume a spherical body? Does this only work for the WGS84 Earth ellipsoid? Or is it independent of the ellipsoid?From my understanding of the formula, the parameters for the ellipsoid (semimajor axes, flattening, etc.) are not taken into account at all in the calculation. Does this calculation assume a spherical body? Does this only work for the WGS84 Earth ellipsoid? Or is it independent of the ellipsoid? From my understanding of the formula, the parameters for the ellipsoid (semimajor axes, flattening, etc.) are not taken into account at all in the calculation. Does this calculation assume a spherical body? Does this only work for the WGS84 Earth ellipsoid? Or is it independent of the ellipsoid? ellipsoid, coordinate conversions, enu2ecefv, vectors MATLAB Answers — New Questions
how does this equation solve for x? it’s the intersection between a line and a hyperbola – hopefully
s*x+i = (x^2*v^2/w^2+v^2)^(1/2)s*x+i = (x^2*v^2/w^2+v^2)^(1/2) s*x+i = (x^2*v^2/w^2+v^2)^(1/2) hyperbola interection MATLAB Answers — New Questions
REGARDING THE PLOT IN MATHLAB2TIKZ
x = -5:0.2:5;
t = 0:0.02:1;
C1 = sin(x’ * t); % Example data
surf(x, t, C1);
xlabel(‘x’);
ylabel(‘t’);
zlabel(‘eta(x,t)’);
title(‘Surface Plot of eta(x,t)’);
% Export the plot as a TikZ file
matlab2tikz(‘figure1.tikz’, ‘height’, ‘figureheight’, ‘width’, ‘figurewidth’);
%%%%%%%%%%%%%%%%%%%%%%%%%%55
WHENEVER I USE THE matlab2tikz THE FIGURE IS GENRATE FOR THE FIRST COMMAND BUT USING MATLAB2TIKZ IT IS THE FOLLOWING MSG IS DISPLAYED
You will need pgfplots version 1.12 or newer to compile the TikZ output
Do i need to install pgfplot in MATLAB .If yes how ?x = -5:0.2:5;
t = 0:0.02:1;
C1 = sin(x’ * t); % Example data
surf(x, t, C1);
xlabel(‘x’);
ylabel(‘t’);
zlabel(‘eta(x,t)’);
title(‘Surface Plot of eta(x,t)’);
% Export the plot as a TikZ file
matlab2tikz(‘figure1.tikz’, ‘height’, ‘figureheight’, ‘width’, ‘figurewidth’);
%%%%%%%%%%%%%%%%%%%%%%%%%%55
WHENEVER I USE THE matlab2tikz THE FIGURE IS GENRATE FOR THE FIRST COMMAND BUT USING MATLAB2TIKZ IT IS THE FOLLOWING MSG IS DISPLAYED
You will need pgfplots version 1.12 or newer to compile the TikZ output
Do i need to install pgfplot in MATLAB .If yes how ? x = -5:0.2:5;
t = 0:0.02:1;
C1 = sin(x’ * t); % Example data
surf(x, t, C1);
xlabel(‘x’);
ylabel(‘t’);
zlabel(‘eta(x,t)’);
title(‘Surface Plot of eta(x,t)’);
% Export the plot as a TikZ file
matlab2tikz(‘figure1.tikz’, ‘height’, ‘figureheight’, ‘width’, ‘figurewidth’);
%%%%%%%%%%%%%%%%%%%%%%%%%%55
WHENEVER I USE THE matlab2tikz THE FIGURE IS GENRATE FOR THE FIRST COMMAND BUT USING MATLAB2TIKZ IT IS THE FOLLOWING MSG IS DISPLAYED
You will need pgfplots version 1.12 or newer to compile the TikZ output
Do i need to install pgfplot in MATLAB .If yes how ? matlab2tikz MATLAB Answers — New Questions
Prediction time NN on STM board
Good morning All,
I would need to compare the computational times required by a NN to process a fixed length signal (3 channels- length: 516 elements) onboard of a STM microcontroller.
For this reason, I created a model with:
a fromworkspace block to collect three fixed length signals,
a stateful-regression-predict block( that recalls the NNs stored in a .mat file)
a simout block (please check the attached figure).
As I need to specify timestamps for each time-step of the sequence, I provide data as 516×4 array (first column is the specified time, the other three columns are the three channels of the input signal). This results in the model predicting the output at the corresponding timestamps with real-time. However, I would like to know the time that the NN takes to process the entire signals not in real-time, just as it was a simulation run on the STM board.
Do you have any clue on how to achieve this result?
I tried to check the "Measure task execution time" option in Hardware Settings/Code Generation/Verification. However, an error "Code generation information file does not exist." displayed while deployng the model to the STM Nucloeo board. It came out the this is a bug of Versione 2022 and 2023. Therefore, I switched to Version 2021, however, even if the model was deployed, once I opened the Data Inspector but no information about execution time is reported. Do you know any viable workaround?
Many thanks in advance
Best regards,
GiovanniGood morning All,
I would need to compare the computational times required by a NN to process a fixed length signal (3 channels- length: 516 elements) onboard of a STM microcontroller.
For this reason, I created a model with:
a fromworkspace block to collect three fixed length signals,
a stateful-regression-predict block( that recalls the NNs stored in a .mat file)
a simout block (please check the attached figure).
As I need to specify timestamps for each time-step of the sequence, I provide data as 516×4 array (first column is the specified time, the other three columns are the three channels of the input signal). This results in the model predicting the output at the corresponding timestamps with real-time. However, I would like to know the time that the NN takes to process the entire signals not in real-time, just as it was a simulation run on the STM board.
Do you have any clue on how to achieve this result?
I tried to check the "Measure task execution time" option in Hardware Settings/Code Generation/Verification. However, an error "Code generation information file does not exist." displayed while deployng the model to the STM Nucloeo board. It came out the this is a bug of Versione 2022 and 2023. Therefore, I switched to Version 2021, however, even if the model was deployed, once I opened the Data Inspector but no information about execution time is reported. Do you know any viable workaround?
Many thanks in advance
Best regards,
Giovanni Good morning All,
I would need to compare the computational times required by a NN to process a fixed length signal (3 channels- length: 516 elements) onboard of a STM microcontroller.
For this reason, I created a model with:
a fromworkspace block to collect three fixed length signals,
a stateful-regression-predict block( that recalls the NNs stored in a .mat file)
a simout block (please check the attached figure).
As I need to specify timestamps for each time-step of the sequence, I provide data as 516×4 array (first column is the specified time, the other three columns are the three channels of the input signal). This results in the model predicting the output at the corresponding timestamps with real-time. However, I would like to know the time that the NN takes to process the entire signals not in real-time, just as it was a simulation run on the STM board.
Do you have any clue on how to achieve this result?
I tried to check the "Measure task execution time" option in Hardware Settings/Code Generation/Verification. However, an error "Code generation information file does not exist." displayed while deployng the model to the STM Nucloeo board. It came out the this is a bug of Versione 2022 and 2023. Therefore, I switched to Version 2021, however, even if the model was deployed, once I opened the Data Inspector but no information about execution time is reported. Do you know any viable workaround?
Many thanks in advance
Best regards,
Giovanni time profiler, stm32 nucleo board MATLAB Answers — New Questions
How to get a dlgradient result for a blackbox function
I’m working on a tomography reconstruction code using a neural representation, which I’d like to train. After some debugging I discovered that:
(1) you can’t use the dlarrays as input to the radon() function;
(2) dlgradient will not work with untraced variables, therefore all variables must be dlarrays;
(3) Using extractdata() to get the input of the radon() function converted to double will fail because dlgradient will lose its trace.
So now I have a conundrum. I need to compute that gradient. dlgradient() won’t do the job. What’s the best alternative way to do it and have the same format as adamupdate() requires?
See below what my loss function looks like. The way it’s written now it will fail at the Sinogram=radon()… line, because Intensity is a dlarray(). As I previously said, if you fix that by extracting the data, then dlgradient() fails.
Thoughts would be appreciated.
function [loss, gradients]=modelLoss(net, XY, Mask, SinogramRef, theta)
Intensity = predict(net,XY);
Intensity = reshape(Intensity, size(Mask));
Intensity(Mask)=0;
Sinogram=radon(Intensity, theta);
Sinogram=dlarray(Sinogram);
loss = sum((Sinogram(~Mask)-SinogramRef(~Mask)).^2);
loss = loss / sum(~Mask(:));
gradients = dlgradient(loss,net.Learnables);
endI’m working on a tomography reconstruction code using a neural representation, which I’d like to train. After some debugging I discovered that:
(1) you can’t use the dlarrays as input to the radon() function;
(2) dlgradient will not work with untraced variables, therefore all variables must be dlarrays;
(3) Using extractdata() to get the input of the radon() function converted to double will fail because dlgradient will lose its trace.
So now I have a conundrum. I need to compute that gradient. dlgradient() won’t do the job. What’s the best alternative way to do it and have the same format as adamupdate() requires?
See below what my loss function looks like. The way it’s written now it will fail at the Sinogram=radon()… line, because Intensity is a dlarray(). As I previously said, if you fix that by extracting the data, then dlgradient() fails.
Thoughts would be appreciated.
function [loss, gradients]=modelLoss(net, XY, Mask, SinogramRef, theta)
Intensity = predict(net,XY);
Intensity = reshape(Intensity, size(Mask));
Intensity(Mask)=0;
Sinogram=radon(Intensity, theta);
Sinogram=dlarray(Sinogram);
loss = sum((Sinogram(~Mask)-SinogramRef(~Mask)).^2);
loss = loss / sum(~Mask(:));
gradients = dlgradient(loss,net.Learnables);
end I’m working on a tomography reconstruction code using a neural representation, which I’d like to train. After some debugging I discovered that:
(1) you can’t use the dlarrays as input to the radon() function;
(2) dlgradient will not work with untraced variables, therefore all variables must be dlarrays;
(3) Using extractdata() to get the input of the radon() function converted to double will fail because dlgradient will lose its trace.
So now I have a conundrum. I need to compute that gradient. dlgradient() won’t do the job. What’s the best alternative way to do it and have the same format as adamupdate() requires?
See below what my loss function looks like. The way it’s written now it will fail at the Sinogram=radon()… line, because Intensity is a dlarray(). As I previously said, if you fix that by extracting the data, then dlgradient() fails.
Thoughts would be appreciated.
function [loss, gradients]=modelLoss(net, XY, Mask, SinogramRef, theta)
Intensity = predict(net,XY);
Intensity = reshape(Intensity, size(Mask));
Intensity(Mask)=0;
Sinogram=radon(Intensity, theta);
Sinogram=dlarray(Sinogram);
loss = sum((Sinogram(~Mask)-SinogramRef(~Mask)).^2);
loss = loss / sum(~Mask(:));
gradients = dlgradient(loss,net.Learnables);
end deep learning, neural network, radon MATLAB Answers — New Questions
What are the differences between fitrnet and trainnet?
I am trying to perform regression on a set of data X (size 52048 x 4) with responses Y (size 52048 x 1).
If I perform a linear regression using mvregress(X,Y), I get a model with a coefficient of determination of 0.70.
If I train a neural network using fitrnet(X,Y), I get a model with a coefficient of determination of about 0.75.
mdl2 = fitrnet(X,Y);
I would like more customizability than what fitrnet offers, so I am trying to use trainnet. To make sure that I am using it correctly, I wanted to recreate the result from fitrnet using trainnet, so I set up the trainnet input parameters to match the defaults from fitrnet:
layers = [
featureInputLayer(size(X,2))
fullyConnectedLayer(10)
reluLayer
fullyConnectedLayer(1)];
options = trainingOptions(‘lbfgs’, GradientTolerance=1e-6, StepTolerance=1e-6);
mdl3 = trainnet(X,Y,layers,’mse’,options);
When I run this, after a few iterations I get a "Training stopped" message and the output model has a coefficient of determination less than 0.30. Sometimes the stoppage message says "Step tolerance reached" and sometimes it says "Suitable learning rate not found".
However, if I initialize the weights and biases for trainnet using the weights and biases learned by fitrnet, trainnet immediately recognizes this as an optimal solution and outputs "Training stopped: Suitable learning rate not found" without making any modification to the weights or biases.
layers = [
featureInputLayer(size(X,2))
fullyConnectedLayer(10, ‘Weights’, mdl2.LayerWeights{1}, ‘Bias’, mdl2.LayerBiases{1})
reluLayer
fullyConnectedLayer(1, ‘Weights’, mdl2.LayerWeights{2}, ‘Bias’, mdl2.LayerBiases{2})];
mdl4 = trainnet(X,Y,layers,’mse’,options);
How is it that trainnet can recognize the solution from fitrnet as optimal, but cannot recreate a similar result using what seems to be identical input parameters?I am trying to perform regression on a set of data X (size 52048 x 4) with responses Y (size 52048 x 1).
If I perform a linear regression using mvregress(X,Y), I get a model with a coefficient of determination of 0.70.
If I train a neural network using fitrnet(X,Y), I get a model with a coefficient of determination of about 0.75.
mdl2 = fitrnet(X,Y);
I would like more customizability than what fitrnet offers, so I am trying to use trainnet. To make sure that I am using it correctly, I wanted to recreate the result from fitrnet using trainnet, so I set up the trainnet input parameters to match the defaults from fitrnet:
layers = [
featureInputLayer(size(X,2))
fullyConnectedLayer(10)
reluLayer
fullyConnectedLayer(1)];
options = trainingOptions(‘lbfgs’, GradientTolerance=1e-6, StepTolerance=1e-6);
mdl3 = trainnet(X,Y,layers,’mse’,options);
When I run this, after a few iterations I get a "Training stopped" message and the output model has a coefficient of determination less than 0.30. Sometimes the stoppage message says "Step tolerance reached" and sometimes it says "Suitable learning rate not found".
However, if I initialize the weights and biases for trainnet using the weights and biases learned by fitrnet, trainnet immediately recognizes this as an optimal solution and outputs "Training stopped: Suitable learning rate not found" without making any modification to the weights or biases.
layers = [
featureInputLayer(size(X,2))
fullyConnectedLayer(10, ‘Weights’, mdl2.LayerWeights{1}, ‘Bias’, mdl2.LayerBiases{1})
reluLayer
fullyConnectedLayer(1, ‘Weights’, mdl2.LayerWeights{2}, ‘Bias’, mdl2.LayerBiases{2})];
mdl4 = trainnet(X,Y,layers,’mse’,options);
How is it that trainnet can recognize the solution from fitrnet as optimal, but cannot recreate a similar result using what seems to be identical input parameters? I am trying to perform regression on a set of data X (size 52048 x 4) with responses Y (size 52048 x 1).
If I perform a linear regression using mvregress(X,Y), I get a model with a coefficient of determination of 0.70.
If I train a neural network using fitrnet(X,Y), I get a model with a coefficient of determination of about 0.75.
mdl2 = fitrnet(X,Y);
I would like more customizability than what fitrnet offers, so I am trying to use trainnet. To make sure that I am using it correctly, I wanted to recreate the result from fitrnet using trainnet, so I set up the trainnet input parameters to match the defaults from fitrnet:
layers = [
featureInputLayer(size(X,2))
fullyConnectedLayer(10)
reluLayer
fullyConnectedLayer(1)];
options = trainingOptions(‘lbfgs’, GradientTolerance=1e-6, StepTolerance=1e-6);
mdl3 = trainnet(X,Y,layers,’mse’,options);
When I run this, after a few iterations I get a "Training stopped" message and the output model has a coefficient of determination less than 0.30. Sometimes the stoppage message says "Step tolerance reached" and sometimes it says "Suitable learning rate not found".
However, if I initialize the weights and biases for trainnet using the weights and biases learned by fitrnet, trainnet immediately recognizes this as an optimal solution and outputs "Training stopped: Suitable learning rate not found" without making any modification to the weights or biases.
layers = [
featureInputLayer(size(X,2))
fullyConnectedLayer(10, ‘Weights’, mdl2.LayerWeights{1}, ‘Bias’, mdl2.LayerBiases{1})
reluLayer
fullyConnectedLayer(1, ‘Weights’, mdl2.LayerWeights{2}, ‘Bias’, mdl2.LayerBiases{2})];
mdl4 = trainnet(X,Y,layers,’mse’,options);
How is it that trainnet can recognize the solution from fitrnet as optimal, but cannot recreate a similar result using what seems to be identical input parameters? fitrnet, trainnet MATLAB Answers — New Questions