Category: Matlab
Category Archives: Matlab
Need help with homework.
This is only my first couple of days using MATLAB. Basically I am trying to make a little temperature conversion program however the displayed answer is always in the form of a 1 x 2 matrix. Any advice is appreciated.
% prompt for user to choose which conversion
chosen_temp = input(‘What is ur chosen conversion, Celsius to Farenheit (1) or Farenheit to Celsius (2): ‘,’s’);
% using that answer to determine which formula is needed and then the
% converted answer
switch chosen_temp
case ‘1’
disp(‘Celsius to Farenheit’)
initial_temp = input(‘Enter the temperature you would like to convert in Celsius:’, ‘s’);
temperature = initial_temp * 9 / 5 + 32
case ‘2’
disp(‘Farenheit to Celsius’)
initial_temp = input(‘Enter the temperature you would like to convert in Farenheit:’, ‘s’);
temperature = (initial_temp – 32) * (5 / 9)
endThis is only my first couple of days using MATLAB. Basically I am trying to make a little temperature conversion program however the displayed answer is always in the form of a 1 x 2 matrix. Any advice is appreciated.
% prompt for user to choose which conversion
chosen_temp = input(‘What is ur chosen conversion, Celsius to Farenheit (1) or Farenheit to Celsius (2): ‘,’s’);
% using that answer to determine which formula is needed and then the
% converted answer
switch chosen_temp
case ‘1’
disp(‘Celsius to Farenheit’)
initial_temp = input(‘Enter the temperature you would like to convert in Celsius:’, ‘s’);
temperature = initial_temp * 9 / 5 + 32
case ‘2’
disp(‘Farenheit to Celsius’)
initial_temp = input(‘Enter the temperature you would like to convert in Farenheit:’, ‘s’);
temperature = (initial_temp – 32) * (5 / 9)
end This is only my first couple of days using MATLAB. Basically I am trying to make a little temperature conversion program however the displayed answer is always in the form of a 1 x 2 matrix. Any advice is appreciated.
% prompt for user to choose which conversion
chosen_temp = input(‘What is ur chosen conversion, Celsius to Farenheit (1) or Farenheit to Celsius (2): ‘,’s’);
% using that answer to determine which formula is needed and then the
% converted answer
switch chosen_temp
case ‘1’
disp(‘Celsius to Farenheit’)
initial_temp = input(‘Enter the temperature you would like to convert in Celsius:’, ‘s’);
temperature = initial_temp * 9 / 5 + 32
case ‘2’
disp(‘Farenheit to Celsius’)
initial_temp = input(‘Enter the temperature you would like to convert in Farenheit:’, ‘s’);
temperature = (initial_temp – 32) * (5 / 9)
end transferred MATLAB Answers — New Questions
Is there a Matlab command to check the expiration date of my license?
I’d like to follow the expiration date of my Matlab license from within Matlab. Is there a Matlab command to check the expiration date of my license?I’d like to follow the expiration date of my Matlab license from within Matlab. Is there a Matlab command to check the expiration date of my license? I’d like to follow the expiration date of my Matlab license from within Matlab. Is there a Matlab command to check the expiration date of my license? license, license expiration MATLAB Answers — New Questions
Classification for seperate training and testing dataset
Hello gyus,
I extract 20 features for 8 images(which are 8 diseases) and then I made a .csv file of these features.I have also an another .csv file
with these features from a dataset of 3000 images. So I have the trining and the testing dataset. I want to classificate the 3000 images
with the 8 diseases from the the first .csv file. Can i use the tool of classification learner or only writing code?
Thanks in advance!Hello gyus,
I extract 20 features for 8 images(which are 8 diseases) and then I made a .csv file of these features.I have also an another .csv file
with these features from a dataset of 3000 images. So I have the trining and the testing dataset. I want to classificate the 3000 images
with the 8 diseases from the the first .csv file. Can i use the tool of classification learner or only writing code?
Thanks in advance! Hello gyus,
I extract 20 features for 8 images(which are 8 diseases) and then I made a .csv file of these features.I have also an another .csv file
with these features from a dataset of 3000 images. So I have the trining and the testing dataset. I want to classificate the 3000 images
with the 8 diseases from the the first .csv file. Can i use the tool of classification learner or only writing code?
Thanks in advance! classificationseperate dataclassification tooltesting datatraining datafeauturescsv file MATLAB Answers — New Questions
how to ensemble 5 different deep learning model with majority voting?
here i saw ensemble deep learning models and they get better results in ensemble learning
https://blogs.mathworks.com/deep-learning/2019/06/03/ensemble-learning/
now i try 5 different deep learning system (for example: resnet, darknet, xception, alexnet, sequeezneet) for my image dataset (for example tumor detection healthy show "0" tumour shows"1" in dataset. i get accuracyresults for these networks but i coudn’t find prediction matrix. so my aim is applying majority voting on these 5 deep learning networks and improve my results?
do you have any suggestions?here i saw ensemble deep learning models and they get better results in ensemble learning
https://blogs.mathworks.com/deep-learning/2019/06/03/ensemble-learning/
now i try 5 different deep learning system (for example: resnet, darknet, xception, alexnet, sequeezneet) for my image dataset (for example tumor detection healthy show "0" tumour shows"1" in dataset. i get accuracyresults for these networks but i coudn’t find prediction matrix. so my aim is applying majority voting on these 5 deep learning networks and improve my results?
do you have any suggestions? here i saw ensemble deep learning models and they get better results in ensemble learning
https://blogs.mathworks.com/deep-learning/2019/06/03/ensemble-learning/
now i try 5 different deep learning system (for example: resnet, darknet, xception, alexnet, sequeezneet) for my image dataset (for example tumor detection healthy show "0" tumour shows"1" in dataset. i get accuracyresults for these networks but i coudn’t find prediction matrix. so my aim is applying majority voting on these 5 deep learning networks and improve my results?
do you have any suggestions? ensemble, deep learning MATLAB Answers — New Questions
Logistic Growth Model – Code and Plot
I need to plot a differential equation that shows logistic growth. The equation is: P=(K*A*e^r*t)/(1+A*e^r*t)
where K is the carrying capacity, a constant, and K = 1,704,885 and A = 0.0122.
I need the correct code so that I can solve for r, as well as put different t to find the population at varying times.
I also need to plot the solution. Thank you for any help!I need to plot a differential equation that shows logistic growth. The equation is: P=(K*A*e^r*t)/(1+A*e^r*t)
where K is the carrying capacity, a constant, and K = 1,704,885 and A = 0.0122.
I need the correct code so that I can solve for r, as well as put different t to find the population at varying times.
I also need to plot the solution. Thank you for any help! I need to plot a differential equation that shows logistic growth. The equation is: P=(K*A*e^r*t)/(1+A*e^r*t)
where K is the carrying capacity, a constant, and K = 1,704,885 and A = 0.0122.
I need the correct code so that I can solve for r, as well as put different t to find the population at varying times.
I also need to plot the solution. Thank you for any help! logistic growth, carrying capacity MATLAB Answers — New Questions
MATLAB GUI does not finish execution when called from another MATLAB based GUI.
Hi Everyone,
I have a MATLAB R2020b gui based application which basically is a menu with buttons and each button press is another MATLAB GUI based executable. The problem is that when I run the main wrapper GUI and press a button, it successfuly launches the executable associated with that. The inner gui based executable is supposed to interface with HW and collect data, save and close and return back the execution to the main GUI. However the problem is that once the inner gui executable saves the data using the save function, it somehow gets frozen, hangs. Nothing happens.
Now here are some other strange observations.
When I run the same deployed setup with extended screens connected to my laptop, it works.
When I run the inner gui directly by double clicking it instead of calling it as a button press from the outer gui, it works.
If I comment out the save function inside the inner GUI, the data doesn’t get saved but the program executes and it works.
I have not been able to undestand this weird behavior. Has someone encountered this behavior before ?
Here is the code inside the launcher.exe that executes on a button press and calls another GUI (executbable)
function abc_Callback(hObject, eventdata, handles)
handles.abc.Enable = ‘off’;
pause(0.2)
try
executablePath = fullfile(handles.rootdirectory, ‘folder1’, ‘folder2’, ‘abc.exe’);
command = sprintf(‘"%s"’, executablePath);
[status] = system(execFileNameWithExt);
catch e
disp(e)
end
handles.abc.Enable = ‘on’;
Also here is where the save function is run. I added some debug lines before and after the save function and realized that
msgbox(‘calling "save" function inside generatereport’);
save(fullfile(res.Report.reportDir,reportName),’res’);
msgbox(‘executed the "save" function inside generatereport, now on line 99’);
now the 2nd msgbox never gets executed. However the save function does save the res object currently at the desired location.
How do you think I should try to debug this problem ? Should i use the logs ?Hi Everyone,
I have a MATLAB R2020b gui based application which basically is a menu with buttons and each button press is another MATLAB GUI based executable. The problem is that when I run the main wrapper GUI and press a button, it successfuly launches the executable associated with that. The inner gui based executable is supposed to interface with HW and collect data, save and close and return back the execution to the main GUI. However the problem is that once the inner gui executable saves the data using the save function, it somehow gets frozen, hangs. Nothing happens.
Now here are some other strange observations.
When I run the same deployed setup with extended screens connected to my laptop, it works.
When I run the inner gui directly by double clicking it instead of calling it as a button press from the outer gui, it works.
If I comment out the save function inside the inner GUI, the data doesn’t get saved but the program executes and it works.
I have not been able to undestand this weird behavior. Has someone encountered this behavior before ?
Here is the code inside the launcher.exe that executes on a button press and calls another GUI (executbable)
function abc_Callback(hObject, eventdata, handles)
handles.abc.Enable = ‘off’;
pause(0.2)
try
executablePath = fullfile(handles.rootdirectory, ‘folder1’, ‘folder2’, ‘abc.exe’);
command = sprintf(‘"%s"’, executablePath);
[status] = system(execFileNameWithExt);
catch e
disp(e)
end
handles.abc.Enable = ‘on’;
Also here is where the save function is run. I added some debug lines before and after the save function and realized that
msgbox(‘calling "save" function inside generatereport’);
save(fullfile(res.Report.reportDir,reportName),’res’);
msgbox(‘executed the "save" function inside generatereport, now on line 99’);
now the 2nd msgbox never gets executed. However the save function does save the res object currently at the desired location.
How do you think I should try to debug this problem ? Should i use the logs ? Hi Everyone,
I have a MATLAB R2020b gui based application which basically is a menu with buttons and each button press is another MATLAB GUI based executable. The problem is that when I run the main wrapper GUI and press a button, it successfuly launches the executable associated with that. The inner gui based executable is supposed to interface with HW and collect data, save and close and return back the execution to the main GUI. However the problem is that once the inner gui executable saves the data using the save function, it somehow gets frozen, hangs. Nothing happens.
Now here are some other strange observations.
When I run the same deployed setup with extended screens connected to my laptop, it works.
When I run the inner gui directly by double clicking it instead of calling it as a button press from the outer gui, it works.
If I comment out the save function inside the inner GUI, the data doesn’t get saved but the program executes and it works.
I have not been able to undestand this weird behavior. Has someone encountered this behavior before ?
Here is the code inside the launcher.exe that executes on a button press and calls another GUI (executbable)
function abc_Callback(hObject, eventdata, handles)
handles.abc.Enable = ‘off’;
pause(0.2)
try
executablePath = fullfile(handles.rootdirectory, ‘folder1’, ‘folder2’, ‘abc.exe’);
command = sprintf(‘"%s"’, executablePath);
[status] = system(execFileNameWithExt);
catch e
disp(e)
end
handles.abc.Enable = ‘on’;
Also here is where the save function is run. I added some debug lines before and after the save function and realized that
msgbox(‘calling "save" function inside generatereport’);
save(fullfile(res.Report.reportDir,reportName),’res’);
msgbox(‘executed the "save" function inside generatereport, now on line 99’);
now the 2nd msgbox never gets executed. However the save function does save the res object currently at the desired location.
How do you think I should try to debug this problem ? Should i use the logs ? r2020b, gui, guide, matlab, application MATLAB Answers — New Questions
Unable to resolve the name cv.getOptimalNewCameraMatrix.
I do not solve this problem. I am trying to solve in many ways. Please anyone help me.
I find this problem:
Unable to resolve the name cv.getOptimalNewCameraMatrix.
Error in undistortion>undistorb_images (line 92)
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0,
[width,height]);
Error in undistortion (line 1)
undistorb_images([], []);
undistorb_images([], []);
function [tvec, rvec, camera_matrix, dist] = read_wp2c(input_name)
%input_name = "output_wp2camera.json";
raw = fileread(input_name);
input_params = jsondecode(raw);
camera_matrix = input_params.camera_matrix;
dist = input_params.dist_coefs;
tvec_json = input_params.translational_vectors;
%tvec = struct2cell(tvec_json);
rvec_json = input_params.rotational_vectors;
%rvec = struct2cell(rvec_json);
tvec = [];
rvec = [];
len = length(tvec_json);
for i = 1:len
%tvec.append(array(tvec_json(image + string(i))))
%tvec.append.tvec_json(i);
tvec = struct2cell(tvec_json(i));
%[A{:}]
%tvec.append(input_params.translational_vectors.image0);
%rvec.append(array(rvec_json(image + string(i))));
rvec = struct2cell(rvec_json(i));
end
end
function undistorb_images(inputParams, result)
%if result is None:
if isempty(result)
input_name = "output_wp2camera.json";
[tvec, rvec, camera_matrix, dist] = read_wp2c(input_name);
else
tvec = result(4);
rvec = result(3);
camera_matrix = result(1);
dist = result(2);
end
if isempty(inputParams)
image_path = "images";
else
image_path = inputParams.opencv_storage.settings.Images_Folder;
end
%image_files = [];
files = [dir(fullfile(image_path,’*.jpg’)); dir(fullfile(image_path,’*.png’)); dir(fullfile(image_path,’*.jpeg’)); dir(fullfile(image_path,’*.PNG’))];
%files = dir(fullfile(image_path, ‘*.(jpg|png)’));
L = length(files);
% kk=0;
% for i=1:L
% file=files(i).name;
% image_files = [image_files, file]
%
%
% end
%disp(image_files)
% for f = dir(image_path)
% %ext = image_path(split(lower(f)));
% %disp(f)
% %if f.endsWith([".jpg",".jpeg",".png", ".PNG"])
% % image_files.append(f);
% %end
% end
image_file_name = [];
if ~isempty(files)
for i=1:L
file=files(i).name;
image_file_name = [image_file_name,file];
%disp(image_file_name)
image = imread(image_path + "" + file);
%disp(image);
% [imagePoints, boardSize] = detectCheckerboardPoints(image_file_name);
% squareSize = 29;
% worldPoints = generateCheckerboardPoints(boardSize, squareSize);
%
% I = readimage(image, 1);
% imageSize = [size(I,1), size(I,2)];
% [params, ~, estimationErrors] = estimateCameraParameters(imagePoinsts, worldPoints, ‘ImageSize’);
[height, width] = size(image);
%disp(string(height) + " " + string(width))
%[newCameraMatrix,w] = cv.getOptimalNewCameraMatrix(cameraMatrix, dist, [width,height]);
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0, [width,height]);
%dst = cv2.undistort(image, camera_matrix, dist, None, newcameramtx)
% imageFileNames{i} = fullfile(matlabroot,’toolbox’,’vision’,’visiondata’,’calibration’,’webcam’,image_file_name);
% [imagePoints,~,imagesUsed] = detectCheckerboardPoints(imageFileNames, ‘PartialDetections’, false);
% imageFileNames = imageFileNames(imagesUsed);
% for i = 1:numel(imageFileNames)
% I = imread(imageFileNames{i});
% subplot(2, 2, i);
% imshow(I);
% hold on;
% plot(imagePoints(:,1,i),imagePoints(:,2,i),’ro’);
% end
[mapx, mapy] = cv.initUndistortRectifyMap(camera_matrix, dist, None, newcameramtx, [width,height], 5);
dst = cv.remap(image, mapx, mapy, INTER_LINEAR);
x, y, w, h = roi;
dst = dst(y:y+h, x:x+w);
[height, width] = size(dst);
print(string(height) + " " + string(width));
imwrite("undistortion/" + file, dst);
end
end
endI do not solve this problem. I am trying to solve in many ways. Please anyone help me.
I find this problem:
Unable to resolve the name cv.getOptimalNewCameraMatrix.
Error in undistortion>undistorb_images (line 92)
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0,
[width,height]);
Error in undistortion (line 1)
undistorb_images([], []);
undistorb_images([], []);
function [tvec, rvec, camera_matrix, dist] = read_wp2c(input_name)
%input_name = "output_wp2camera.json";
raw = fileread(input_name);
input_params = jsondecode(raw);
camera_matrix = input_params.camera_matrix;
dist = input_params.dist_coefs;
tvec_json = input_params.translational_vectors;
%tvec = struct2cell(tvec_json);
rvec_json = input_params.rotational_vectors;
%rvec = struct2cell(rvec_json);
tvec = [];
rvec = [];
len = length(tvec_json);
for i = 1:len
%tvec.append(array(tvec_json(image + string(i))))
%tvec.append.tvec_json(i);
tvec = struct2cell(tvec_json(i));
%[A{:}]
%tvec.append(input_params.translational_vectors.image0);
%rvec.append(array(rvec_json(image + string(i))));
rvec = struct2cell(rvec_json(i));
end
end
function undistorb_images(inputParams, result)
%if result is None:
if isempty(result)
input_name = "output_wp2camera.json";
[tvec, rvec, camera_matrix, dist] = read_wp2c(input_name);
else
tvec = result(4);
rvec = result(3);
camera_matrix = result(1);
dist = result(2);
end
if isempty(inputParams)
image_path = "images";
else
image_path = inputParams.opencv_storage.settings.Images_Folder;
end
%image_files = [];
files = [dir(fullfile(image_path,’*.jpg’)); dir(fullfile(image_path,’*.png’)); dir(fullfile(image_path,’*.jpeg’)); dir(fullfile(image_path,’*.PNG’))];
%files = dir(fullfile(image_path, ‘*.(jpg|png)’));
L = length(files);
% kk=0;
% for i=1:L
% file=files(i).name;
% image_files = [image_files, file]
%
%
% end
%disp(image_files)
% for f = dir(image_path)
% %ext = image_path(split(lower(f)));
% %disp(f)
% %if f.endsWith([".jpg",".jpeg",".png", ".PNG"])
% % image_files.append(f);
% %end
% end
image_file_name = [];
if ~isempty(files)
for i=1:L
file=files(i).name;
image_file_name = [image_file_name,file];
%disp(image_file_name)
image = imread(image_path + "" + file);
%disp(image);
% [imagePoints, boardSize] = detectCheckerboardPoints(image_file_name);
% squareSize = 29;
% worldPoints = generateCheckerboardPoints(boardSize, squareSize);
%
% I = readimage(image, 1);
% imageSize = [size(I,1), size(I,2)];
% [params, ~, estimationErrors] = estimateCameraParameters(imagePoinsts, worldPoints, ‘ImageSize’);
[height, width] = size(image);
%disp(string(height) + " " + string(width))
%[newCameraMatrix,w] = cv.getOptimalNewCameraMatrix(cameraMatrix, dist, [width,height]);
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0, [width,height]);
%dst = cv2.undistort(image, camera_matrix, dist, None, newcameramtx)
% imageFileNames{i} = fullfile(matlabroot,’toolbox’,’vision’,’visiondata’,’calibration’,’webcam’,image_file_name);
% [imagePoints,~,imagesUsed] = detectCheckerboardPoints(imageFileNames, ‘PartialDetections’, false);
% imageFileNames = imageFileNames(imagesUsed);
% for i = 1:numel(imageFileNames)
% I = imread(imageFileNames{i});
% subplot(2, 2, i);
% imshow(I);
% hold on;
% plot(imagePoints(:,1,i),imagePoints(:,2,i),’ro’);
% end
[mapx, mapy] = cv.initUndistortRectifyMap(camera_matrix, dist, None, newcameramtx, [width,height], 5);
dst = cv.remap(image, mapx, mapy, INTER_LINEAR);
x, y, w, h = roi;
dst = dst(y:y+h, x:x+w);
[height, width] = size(dst);
print(string(height) + " " + string(width));
imwrite("undistortion/" + file, dst);
end
end
end I do not solve this problem. I am trying to solve in many ways. Please anyone help me.
I find this problem:
Unable to resolve the name cv.getOptimalNewCameraMatrix.
Error in undistortion>undistorb_images (line 92)
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0,
[width,height]);
Error in undistortion (line 1)
undistorb_images([], []);
undistorb_images([], []);
function [tvec, rvec, camera_matrix, dist] = read_wp2c(input_name)
%input_name = "output_wp2camera.json";
raw = fileread(input_name);
input_params = jsondecode(raw);
camera_matrix = input_params.camera_matrix;
dist = input_params.dist_coefs;
tvec_json = input_params.translational_vectors;
%tvec = struct2cell(tvec_json);
rvec_json = input_params.rotational_vectors;
%rvec = struct2cell(rvec_json);
tvec = [];
rvec = [];
len = length(tvec_json);
for i = 1:len
%tvec.append(array(tvec_json(image + string(i))))
%tvec.append.tvec_json(i);
tvec = struct2cell(tvec_json(i));
%[A{:}]
%tvec.append(input_params.translational_vectors.image0);
%rvec.append(array(rvec_json(image + string(i))));
rvec = struct2cell(rvec_json(i));
end
end
function undistorb_images(inputParams, result)
%if result is None:
if isempty(result)
input_name = "output_wp2camera.json";
[tvec, rvec, camera_matrix, dist] = read_wp2c(input_name);
else
tvec = result(4);
rvec = result(3);
camera_matrix = result(1);
dist = result(2);
end
if isempty(inputParams)
image_path = "images";
else
image_path = inputParams.opencv_storage.settings.Images_Folder;
end
%image_files = [];
files = [dir(fullfile(image_path,’*.jpg’)); dir(fullfile(image_path,’*.png’)); dir(fullfile(image_path,’*.jpeg’)); dir(fullfile(image_path,’*.PNG’))];
%files = dir(fullfile(image_path, ‘*.(jpg|png)’));
L = length(files);
% kk=0;
% for i=1:L
% file=files(i).name;
% image_files = [image_files, file]
%
%
% end
%disp(image_files)
% for f = dir(image_path)
% %ext = image_path(split(lower(f)));
% %disp(f)
% %if f.endsWith([".jpg",".jpeg",".png", ".PNG"])
% % image_files.append(f);
% %end
% end
image_file_name = [];
if ~isempty(files)
for i=1:L
file=files(i).name;
image_file_name = [image_file_name,file];
%disp(image_file_name)
image = imread(image_path + "" + file);
%disp(image);
% [imagePoints, boardSize] = detectCheckerboardPoints(image_file_name);
% squareSize = 29;
% worldPoints = generateCheckerboardPoints(boardSize, squareSize);
%
% I = readimage(image, 1);
% imageSize = [size(I,1), size(I,2)];
% [params, ~, estimationErrors] = estimateCameraParameters(imagePoinsts, worldPoints, ‘ImageSize’);
[height, width] = size(image);
%disp(string(height) + " " + string(width))
%[newCameraMatrix,w] = cv.getOptimalNewCameraMatrix(cameraMatrix, dist, [width,height]);
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0, [width,height]);
%dst = cv2.undistort(image, camera_matrix, dist, None, newcameramtx)
% imageFileNames{i} = fullfile(matlabroot,’toolbox’,’vision’,’visiondata’,’calibration’,’webcam’,image_file_name);
% [imagePoints,~,imagesUsed] = detectCheckerboardPoints(imageFileNames, ‘PartialDetections’, false);
% imageFileNames = imageFileNames(imagesUsed);
% for i = 1:numel(imageFileNames)
% I = imread(imageFileNames{i});
% subplot(2, 2, i);
% imshow(I);
% hold on;
% plot(imagePoints(:,1,i),imagePoints(:,2,i),’ro’);
% end
[mapx, mapy] = cv.initUndistortRectifyMap(camera_matrix, dist, None, newcameramtx, [width,height], 5);
dst = cv.remap(image, mapx, mapy, INTER_LINEAR);
x, y, w, h = roi;
dst = dst(y:y+h, x:x+w);
[height, width] = size(dst);
print(string(height) + " " + string(width));
imwrite("undistortion/" + file, dst);
end
end
end image processing, matlab MATLAB Answers — New Questions
Bessel function has problems in converting symbolic function into handle function.
I want to derive the spherical Bessel function, so I first construct the spherical Bessel function by using Bessel function.
,
Because I want to derive the spherical Bessel function, I want to first construct a symbolic expression of the spherical Bessel function, and then use the diff function to get the first derivative, and then convert it into a function handle.
However, when n is large, the symbolic expression of spherical Bessel function has problems(In the figure below, I haven’t derived the spherical Bessel function yet, but there has been a case of non-convergence, so it can be seen that the derivative is also non-convergence):
If I don’t need to find the derivative of Bessel function, then I only need to use the handle to complete this task. I need to construct a function to find the first derivative of spherical Bessel function at any point. Is there any good way?I want to derive the spherical Bessel function, so I first construct the spherical Bessel function by using Bessel function.
,
Because I want to derive the spherical Bessel function, I want to first construct a symbolic expression of the spherical Bessel function, and then use the diff function to get the first derivative, and then convert it into a function handle.
However, when n is large, the symbolic expression of spherical Bessel function has problems(In the figure below, I haven’t derived the spherical Bessel function yet, but there has been a case of non-convergence, so it can be seen that the derivative is also non-convergence):
If I don’t need to find the derivative of Bessel function, then I only need to use the handle to complete this task. I need to construct a function to find the first derivative of spherical Bessel function at any point. Is there any good way? I want to derive the spherical Bessel function, so I first construct the spherical Bessel function by using Bessel function.
,
Because I want to derive the spherical Bessel function, I want to first construct a symbolic expression of the spherical Bessel function, and then use the diff function to get the first derivative, and then convert it into a function handle.
However, when n is large, the symbolic expression of spherical Bessel function has problems(In the figure below, I haven’t derived the spherical Bessel function yet, but there has been a case of non-convergence, so it can be seen that the derivative is also non-convergence):
If I don’t need to find the derivative of Bessel function, then I only need to use the handle to complete this task. I need to construct a function to find the first derivative of spherical Bessel function at any point. Is there any good way? bessel function, numerical method, restrain oneself MATLAB Answers — New Questions
Weird bugs when solving three coupled second order differential equations using ode45
Hi guys, I am new to ode45 so I am very confused about its results. I have good results when solving two coupled differential equations (say, x1 and y ), but when I add one more equation (say x2), then the results are very different and even if I set x2 equation the same as x1, which doesn’t make much sense for me. Here are the codes I used:
eq1 = diff(x1,2) == -2*gamma_ir*omega_ir1*dx1 – omega_ir1^2*x1 + y + 2*x2*y;
eq2 = diff(x2,2) == -2*gamma_ir*omega_ir2*dx2 – omega_ir2^2*x2 + y + 2*x1*y;
eq3 = diff(y,2) == -2*gamma_r*omega_r*dy – omega_r^2*y + x1*x2;
V = odeToVectorField(eq1,eq2,eq3);
M = matlabFunction(V,’vars’, {‘t’,’Y’});
interval = t0;
ySol = ode45(M,interval,y0);
tValues = linspace(interval(1),interval(2),tNum);
sol = deval(ySol,tValues,3);
Thanks in advance!Hi guys, I am new to ode45 so I am very confused about its results. I have good results when solving two coupled differential equations (say, x1 and y ), but when I add one more equation (say x2), then the results are very different and even if I set x2 equation the same as x1, which doesn’t make much sense for me. Here are the codes I used:
eq1 = diff(x1,2) == -2*gamma_ir*omega_ir1*dx1 – omega_ir1^2*x1 + y + 2*x2*y;
eq2 = diff(x2,2) == -2*gamma_ir*omega_ir2*dx2 – omega_ir2^2*x2 + y + 2*x1*y;
eq3 = diff(y,2) == -2*gamma_r*omega_r*dy – omega_r^2*y + x1*x2;
V = odeToVectorField(eq1,eq2,eq3);
M = matlabFunction(V,’vars’, {‘t’,’Y’});
interval = t0;
ySol = ode45(M,interval,y0);
tValues = linspace(interval(1),interval(2),tNum);
sol = deval(ySol,tValues,3);
Thanks in advance! Hi guys, I am new to ode45 so I am very confused about its results. I have good results when solving two coupled differential equations (say, x1 and y ), but when I add one more equation (say x2), then the results are very different and even if I set x2 equation the same as x1, which doesn’t make much sense for me. Here are the codes I used:
eq1 = diff(x1,2) == -2*gamma_ir*omega_ir1*dx1 – omega_ir1^2*x1 + y + 2*x2*y;
eq2 = diff(x2,2) == -2*gamma_ir*omega_ir2*dx2 – omega_ir2^2*x2 + y + 2*x1*y;
eq3 = diff(y,2) == -2*gamma_r*omega_r*dy – omega_r^2*y + x1*x2;
V = odeToVectorField(eq1,eq2,eq3);
M = matlabFunction(V,’vars’, {‘t’,’Y’});
interval = t0;
ySol = ode45(M,interval,y0);
tValues = linspace(interval(1),interval(2),tNum);
sol = deval(ySol,tValues,3);
Thanks in advance! differential equations, ode45 MATLAB Answers — New Questions
How to overlay box plot with distribution histogram in the same graph
I want to overlay box plot on my distribution histogram (something like as shown in the figure). How can I do that?I want to overlay box plot on my distribution histogram (something like as shown in the figure). How can I do that? I want to overlay box plot on my distribution histogram (something like as shown in the figure). How can I do that? box plot, histogram, overlay MATLAB Answers — New Questions
Having Boxplot problem with not defined double type
Hello, I am trying to plot boxplot.
x = [1 2 3 4 5];
y = [1.13465 1.17166 1.19973 1.78338 1.83673
3.96e-12 3.6e-11 0.109991 1.0131 1.57166
0.574522 0.619429 0.685391 1.21099 1.73831
1.27e-11 0.142583 0.308049 0.890379 1.38142
3.5e-12 0.0606085 0.137094 0.565742 0.915032
1.77e-11 0.0206984 0.096124 0.213596 0.548369
0.343735 0.358206 0.386193 1.04343 1.80219
0.342868 0.333045 0.341806 0.760036 1.41684
0.423389 0.412866 0.415499 0.569211 0.564488
4e-12 3.67e-11 0.109991 1.0131 1.57166
0.692851 0.696025 0.704127 1.30321 1.88094
5.5e-11 0.0395349 0.180155 0.639514 1.04088];
boxplot(x,y)
this is the code that I used,
but when I tried to plot, it said
‘The function ‘boxplot’ is not defined for inputs of type ‘double’.
Error occurred: untitled (line 22) boxplot(x,y)’
Can anyone help me to solve the problem?
Thank you!Hello, I am trying to plot boxplot.
x = [1 2 3 4 5];
y = [1.13465 1.17166 1.19973 1.78338 1.83673
3.96e-12 3.6e-11 0.109991 1.0131 1.57166
0.574522 0.619429 0.685391 1.21099 1.73831
1.27e-11 0.142583 0.308049 0.890379 1.38142
3.5e-12 0.0606085 0.137094 0.565742 0.915032
1.77e-11 0.0206984 0.096124 0.213596 0.548369
0.343735 0.358206 0.386193 1.04343 1.80219
0.342868 0.333045 0.341806 0.760036 1.41684
0.423389 0.412866 0.415499 0.569211 0.564488
4e-12 3.67e-11 0.109991 1.0131 1.57166
0.692851 0.696025 0.704127 1.30321 1.88094
5.5e-11 0.0395349 0.180155 0.639514 1.04088];
boxplot(x,y)
this is the code that I used,
but when I tried to plot, it said
‘The function ‘boxplot’ is not defined for inputs of type ‘double’.
Error occurred: untitled (line 22) boxplot(x,y)’
Can anyone help me to solve the problem?
Thank you! Hello, I am trying to plot boxplot.
x = [1 2 3 4 5];
y = [1.13465 1.17166 1.19973 1.78338 1.83673
3.96e-12 3.6e-11 0.109991 1.0131 1.57166
0.574522 0.619429 0.685391 1.21099 1.73831
1.27e-11 0.142583 0.308049 0.890379 1.38142
3.5e-12 0.0606085 0.137094 0.565742 0.915032
1.77e-11 0.0206984 0.096124 0.213596 0.548369
0.343735 0.358206 0.386193 1.04343 1.80219
0.342868 0.333045 0.341806 0.760036 1.41684
0.423389 0.412866 0.415499 0.569211 0.564488
4e-12 3.67e-11 0.109991 1.0131 1.57166
0.692851 0.696025 0.704127 1.30321 1.88094
5.5e-11 0.0395349 0.180155 0.639514 1.04088];
boxplot(x,y)
this is the code that I used,
but when I tried to plot, it said
‘The function ‘boxplot’ is not defined for inputs of type ‘double’.
Error occurred: untitled (line 22) boxplot(x,y)’
Can anyone help me to solve the problem?
Thank you! boxplot, typedouble MATLAB Answers — New Questions
Why is the output from Signal Editor not as expected?
The signal output from Signal Editor does not match the expected signal created in the scenario. Why is this happening?The signal output from Signal Editor does not match the expected signal created in the scenario. Why is this happening? The signal output from Signal Editor does not match the expected signal created in the scenario. Why is this happening? MATLAB Answers — New Questions
how to obtain coefficients and other data from a curve fit object, of the interpolant type, using linear method?
From a set of data, I could easily obtain a curve fit using curveFitter. The fit is of the interpolant type, using linear method. From what I understand, the underlying method is linear triangular interpolation. But then, I’m unable to get the internal data of the model. I mean, there should be triangle boundaries, coefficients and other constants describing the triangular pieces of surface that approximate my data set, but I was unable to read them from the obtained fit.
So, for this particular fit (linear interpolant), how to get the inside data?From a set of data, I could easily obtain a curve fit using curveFitter. The fit is of the interpolant type, using linear method. From what I understand, the underlying method is linear triangular interpolation. But then, I’m unable to get the internal data of the model. I mean, there should be triangle boundaries, coefficients and other constants describing the triangular pieces of surface that approximate my data set, but I was unable to read them from the obtained fit.
So, for this particular fit (linear interpolant), how to get the inside data? From a set of data, I could easily obtain a curve fit using curveFitter. The fit is of the interpolant type, using linear method. From what I understand, the underlying method is linear triangular interpolation. But then, I’m unable to get the internal data of the model. I mean, there should be triangle boundaries, coefficients and other constants describing the triangular pieces of surface that approximate my data set, but I was unable to read them from the obtained fit.
So, for this particular fit (linear interpolant), how to get the inside data? curve fitting, interpolant, linear MATLAB Answers — New Questions
Hide Simulink badge icons
Hello,
When using Simulink Data Dictionary or colouring sample times, badge icons are displayed in the bottom left corner of the Simulink/Stateflow diagram.
I would like to hide or deactivate them.
What is the best way to do this, preferably programmatically?Hello,
When using Simulink Data Dictionary or colouring sample times, badge icons are displayed in the bottom left corner of the Simulink/Stateflow diagram.
I would like to hide or deactivate them.
What is the best way to do this, preferably programmatically? Hello,
When using Simulink Data Dictionary or colouring sample times, badge icons are displayed in the bottom left corner of the Simulink/Stateflow diagram.
I would like to hide or deactivate them.
What is the best way to do this, preferably programmatically? simulink, stateflow, badge, diagram MATLAB Answers — New Questions
How to read a ‘CompactSVMModel’ saved in a .mat file from a C++/Qt program
I tried to save a machine learning model into a .mat file, and then read it from a Qt/C++ application. Following the documentation, I managed to read files containing basic types like double or int. As my model is of type ‘classreg.learning.classif.CompactClassificationSVM’, I wonder if it is still possible to read it.
As and example, i saved this iosnosphere model on matlab
load ionosphere
SVMModel = fitcsvm(X,Y,’Standardize’,true,’ClassNames’,{‘b’,’g’})
CompactSVMModel = compact(SVMModel)
save("CompactSVMModel.mat", "CompactSVMModel")
I imported the relevant library in the CMakeLists.txt
find_package(Matlab "x.xx" EXACT COMPONENTS "MX_LIBRARY" "MAT_LIBRARY" "DATAARRAY_LIBRARY" )
target_link_libraries(target PRIVATE Matlab::mat )
I used the "mat.h" library to open and read the data.
#include "mat.h"
int main () {
std::string stdFilename = "/filepath/CompactSVMModel.mat";
const char *variableName = "CompactSVMModel";
// Open the MAT-File
MATFile *matFile = matOpen(stdFilename.c_str(), "r");
if (!matFile) {
qDebug() << "Error opening MAT file: " << stdFilename;
}
// Read the variable from the MAT-File
mxArray *dataArray = matGetVariable(matFile, variableName);
if (!dataArray) {
qDebug() << "Error reading variable: " << variableName << " from MAT file: " << stdFilename;
}
…
// read a save the diffrent fields into containers
return 0;
}
At the first if statement, matFile is NULL.I tried to save a machine learning model into a .mat file, and then read it from a Qt/C++ application. Following the documentation, I managed to read files containing basic types like double or int. As my model is of type ‘classreg.learning.classif.CompactClassificationSVM’, I wonder if it is still possible to read it.
As and example, i saved this iosnosphere model on matlab
load ionosphere
SVMModel = fitcsvm(X,Y,’Standardize’,true,’ClassNames’,{‘b’,’g’})
CompactSVMModel = compact(SVMModel)
save("CompactSVMModel.mat", "CompactSVMModel")
I imported the relevant library in the CMakeLists.txt
find_package(Matlab "x.xx" EXACT COMPONENTS "MX_LIBRARY" "MAT_LIBRARY" "DATAARRAY_LIBRARY" )
target_link_libraries(target PRIVATE Matlab::mat )
I used the "mat.h" library to open and read the data.
#include "mat.h"
int main () {
std::string stdFilename = "/filepath/CompactSVMModel.mat";
const char *variableName = "CompactSVMModel";
// Open the MAT-File
MATFile *matFile = matOpen(stdFilename.c_str(), "r");
if (!matFile) {
qDebug() << "Error opening MAT file: " << stdFilename;
}
// Read the variable from the MAT-File
mxArray *dataArray = matGetVariable(matFile, variableName);
if (!dataArray) {
qDebug() << "Error reading variable: " << variableName << " from MAT file: " << stdFilename;
}
…
// read a save the diffrent fields into containers
return 0;
}
At the first if statement, matFile is NULL. I tried to save a machine learning model into a .mat file, and then read it from a Qt/C++ application. Following the documentation, I managed to read files containing basic types like double or int. As my model is of type ‘classreg.learning.classif.CompactClassificationSVM’, I wonder if it is still possible to read it.
As and example, i saved this iosnosphere model on matlab
load ionosphere
SVMModel = fitcsvm(X,Y,’Standardize’,true,’ClassNames’,{‘b’,’g’})
CompactSVMModel = compact(SVMModel)
save("CompactSVMModel.mat", "CompactSVMModel")
I imported the relevant library in the CMakeLists.txt
find_package(Matlab "x.xx" EXACT COMPONENTS "MX_LIBRARY" "MAT_LIBRARY" "DATAARRAY_LIBRARY" )
target_link_libraries(target PRIVATE Matlab::mat )
I used the "mat.h" library to open and read the data.
#include "mat.h"
int main () {
std::string stdFilename = "/filepath/CompactSVMModel.mat";
const char *variableName = "CompactSVMModel";
// Open the MAT-File
MATFile *matFile = matOpen(stdFilename.c_str(), "r");
if (!matFile) {
qDebug() << "Error opening MAT file: " << stdFilename;
}
// Read the variable from the MAT-File
mxArray *dataArray = matGetVariable(matFile, variableName);
if (!dataArray) {
qDebug() << "Error reading variable: " << variableName << " from MAT file: " << stdFilename;
}
…
// read a save the diffrent fields into containers
return 0;
}
At the first if statement, matFile is NULL. matlab, c++, machine learning, matrix MATLAB Answers — New Questions
I am trying to derive an equation for (RLC model) and i am stuck at one point how he get the final equation (12) second part?
Capacitor discharging in RLC series circuit. Equation (8) general solution for the discharging current,
i(t)=e^(-αt) (A cos(ωt)+B sin(ωt)) (8)
Now we will find the constant A and B using the initial condition assuming the capacitor voltage VDC and current IDC. The initial conditions are taken just before the fault occurs.
At t=0
i(0)=I_DC=A
Then the nominal voltage at the initial condition is equal to to the nominal voltage.
Vc(0)=V_DC
To find B take the derivative of the equation (8) we get
(di(t))/dt=e^(-αt) (-α(A cos(ωt)+B sin(ωt) )+ω(B cos(ωt)-A sin(ωt)) (9)
At t=0
(di(0))/dt=-αA+ωB
The initial rate of change of current is equal to
(di(0))/dt=(V_L (0))/L=-αA+ωB
Using
A=I_DC
B=((V_L (0))/L+αI_DC)/ω
Since the RLC is a series circuit and initial conditions are the same thus the current is also the same across R, L, and C.
(V_L (0))/L=I_L=I_DC
B=(I_DC+αA)/ω (10)
Putting the values of A and B in the equation (8) we get
i(t)=e^(-αt) (I_DC cos(ωt)+(I_DC+αA)/ω sin(ωt)) (11)
For the capacitor
1/C i(0)=V_c (0) and for initial condition i(0)=I_DC so 1/C I_DC=V_DC
“A” becomes equal to
A=I_DC=CV_DC
Expressing the equation in terms of the A and B from equation (10)
I_DC=Bω-Aα
So putting in equation (10)
i(t)=[(Bω-αA) cos(ωt)-(Aω+Bα) sin(ωt)]e^(-αt) (12)Capacitor discharging in RLC series circuit. Equation (8) general solution for the discharging current,
i(t)=e^(-αt) (A cos(ωt)+B sin(ωt)) (8)
Now we will find the constant A and B using the initial condition assuming the capacitor voltage VDC and current IDC. The initial conditions are taken just before the fault occurs.
At t=0
i(0)=I_DC=A
Then the nominal voltage at the initial condition is equal to to the nominal voltage.
Vc(0)=V_DC
To find B take the derivative of the equation (8) we get
(di(t))/dt=e^(-αt) (-α(A cos(ωt)+B sin(ωt) )+ω(B cos(ωt)-A sin(ωt)) (9)
At t=0
(di(0))/dt=-αA+ωB
The initial rate of change of current is equal to
(di(0))/dt=(V_L (0))/L=-αA+ωB
Using
A=I_DC
B=((V_L (0))/L+αI_DC)/ω
Since the RLC is a series circuit and initial conditions are the same thus the current is also the same across R, L, and C.
(V_L (0))/L=I_L=I_DC
B=(I_DC+αA)/ω (10)
Putting the values of A and B in the equation (8) we get
i(t)=e^(-αt) (I_DC cos(ωt)+(I_DC+αA)/ω sin(ωt)) (11)
For the capacitor
1/C i(0)=V_c (0) and for initial condition i(0)=I_DC so 1/C I_DC=V_DC
“A” becomes equal to
A=I_DC=CV_DC
Expressing the equation in terms of the A and B from equation (10)
I_DC=Bω-Aα
So putting in equation (10)
i(t)=[(Bω-αA) cos(ωt)-(Aω+Bα) sin(ωt)]e^(-αt) (12) Capacitor discharging in RLC series circuit. Equation (8) general solution for the discharging current,
i(t)=e^(-αt) (A cos(ωt)+B sin(ωt)) (8)
Now we will find the constant A and B using the initial condition assuming the capacitor voltage VDC and current IDC. The initial conditions are taken just before the fault occurs.
At t=0
i(0)=I_DC=A
Then the nominal voltage at the initial condition is equal to to the nominal voltage.
Vc(0)=V_DC
To find B take the derivative of the equation (8) we get
(di(t))/dt=e^(-αt) (-α(A cos(ωt)+B sin(ωt) )+ω(B cos(ωt)-A sin(ωt)) (9)
At t=0
(di(0))/dt=-αA+ωB
The initial rate of change of current is equal to
(di(0))/dt=(V_L (0))/L=-αA+ωB
Using
A=I_DC
B=((V_L (0))/L+αI_DC)/ω
Since the RLC is a series circuit and initial conditions are the same thus the current is also the same across R, L, and C.
(V_L (0))/L=I_L=I_DC
B=(I_DC+αA)/ω (10)
Putting the values of A and B in the equation (8) we get
i(t)=e^(-αt) (I_DC cos(ωt)+(I_DC+αA)/ω sin(ωt)) (11)
For the capacitor
1/C i(0)=V_c (0) and for initial condition i(0)=I_DC so 1/C I_DC=V_DC
“A” becomes equal to
A=I_DC=CV_DC
Expressing the equation in terms of the A and B from equation (10)
I_DC=Bω-Aα
So putting in equation (10)
i(t)=[(Bω-αA) cos(ωt)-(Aω+Bα) sin(ωt)]e^(-αt) (12) matrix, mathematics, electrical, circuit design MATLAB Answers — New Questions
Returning workspace outputs is supported with only single return argument
Dear,
I am trying to run a simulink model in m-code while optimizing ADRC parameters with PSO, but I get an error:
‘Returning workspace outputs is supported with only single return argument’.
The first figure is ‘PSO_ADRC’ code and the second figure is the simulink model ‘ADRC_test’.
Hope someone can help me, thanks.Dear,
I am trying to run a simulink model in m-code while optimizing ADRC parameters with PSO, but I get an error:
‘Returning workspace outputs is supported with only single return argument’.
The first figure is ‘PSO_ADRC’ code and the second figure is the simulink model ‘ADRC_test’.
Hope someone can help me, thanks. Dear,
I am trying to run a simulink model in m-code while optimizing ADRC parameters with PSO, but I get an error:
‘Returning workspace outputs is supported with only single return argument’.
The first figure is ‘PSO_ADRC’ code and the second figure is the simulink model ‘ADRC_test’.
Hope someone can help me, thanks. simulink, matlab MATLAB Answers — New Questions
zipping empty subdirectories
I try to zip a directory which contains empty sub-directories but zip() function ignore the empty ones. Is there way to include the empty subdirectories as well?I try to zip a directory which contains empty sub-directories but zip() function ignore the empty ones. Is there way to include the empty subdirectories as well? I try to zip a directory which contains empty sub-directories but zip() function ignore the empty ones. Is there way to include the empty subdirectories as well? zip MATLAB Answers — New Questions
Solve integral in nested function
hello there,
i am trying to build something like this:
if true
function x = first
x = 5*y
function y = nested
I = @(x) x^2
y = integral(I,0,1)
end
end
end
but there occurs an error stating: ‘Error: Function definitions are not permitted in this context.’
Does anyone know an alternative or sees the misstake i made?
thanks!hello there,
i am trying to build something like this:
if true
function x = first
x = 5*y
function y = nested
I = @(x) x^2
y = integral(I,0,1)
end
end
end
but there occurs an error stating: ‘Error: Function definitions are not permitted in this context.’
Does anyone know an alternative or sees the misstake i made?
thanks! hello there,
i am trying to build something like this:
if true
function x = first
x = 5*y
function y = nested
I = @(x) x^2
y = integral(I,0,1)
end
end
end
but there occurs an error stating: ‘Error: Function definitions are not permitted in this context.’
Does anyone know an alternative or sees the misstake i made?
thanks! integral, nested functions, passing results MATLAB Answers — New Questions
SIMULINK: Set a random seed in the Block Parameters: Random Number GUI
SIMULINK
How do I set a random seed in the user GUI for a random number block? (So I get a random number at each sim run)
ThanksSIMULINK
How do I set a random seed in the user GUI for a random number block? (So I get a random number at each sim run)
Thanks SIMULINK
How do I set a random seed in the user GUI for a random number block? (So I get a random number at each sim run)
Thanks simulink, random number generator MATLAB Answers — New Questions