https://ch.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-03-03T06:25:57Ztag:ch.mathworks.com,2005:Question/7609012021-03-02T20:38:41Z2021-03-03T06:22:51ZI do not understand why I get imaginary numbers as answers to this simultaneous equation I am trying to solve syms x y
eqn1 = 87*sind(x)+ 65*sind(y) == (-92*sind(200))-(73*sind(0))
eqn2 = 87*cosd(x) + 65*cosd(y) == (92*cosd(200)) - (73*cosd(0))
sol = solve(eqn1,eqn2,x,y)
xSol = sol.x
ySol = sol.y
vpa(xSol)
vpa(ySol)mintyfrezhhttps://ch.mathworks.com/matlabcentral/profile/authors/16275419tag:ch.mathworks.com,2005:Question/7612412021-03-03T06:21:29Z2021-03-03T06:21:29ZHow to calculate all the numbers in an array with some conditions?I calculated some radian value of angles from the previouse code.
n = 8;
wl = 1;
d = wl./2;
AF = zeros(1,50);
th= 20;
angle_rad = th*pi./180;
phi= (2.*pi.*d .*sin(angle_rad))./wl;
and usd a for loop to display all the numbers of phi
for a = 1:n
AF = (a-1).*phi
end
The problem is I need the value of phi is restricted between-2pi and 2pi. (The angle value (th) I stated was 20 degree but it can be changed, such as -50 degree)
I am not sure what to do with it, hope to get help from you guys！ Thanks!ZIYI WENGhttps://ch.mathworks.com/matlabcentral/profile/authors/13816818tag:ch.mathworks.com,2005:Question/7612312021-03-03T06:05:53Z2021-03-03T06:25:57ZIndex exceeds the number of array elements (0) error. Help pleaseHi,
Below is my very simple code. What is wrong with this. Could you help me please?
function [E]=mainy()
clc
clear all
syms x t eta zeta xsi m tau epsilon k
for j=1:3
WK=[];
w(j)=j*2*x
end
for k=1:3
UXT=[];
UXT(k)=k*x
end
for i=1:3
E=[];
E=UXT(i)-WK(i)
% E=(UXT(k)-WK(k))/(UXT(k))
end
endOZGUR YILDIRIMhttps://ch.mathworks.com/matlabcentral/profile/authors/10649161tag:ch.mathworks.com,2005:Question/7570642021-02-26T14:25:41Z2021-03-03T06:11:53ZLed Blinking with Zynq Platform I tried the led blinking with zynq's example in matlab 2019a version. I did not have any problems in the HDL Work Flow. But, when I run my model in simulink, I get the error in the photo. Can you help me?
Photo:
serhat yusuf Oztaskinhttps://ch.mathworks.com/matlabcentral/profile/authors/14335914tag:ch.mathworks.com,2005:Question/847942013-08-15T10:10:50Z2021-03-03T06:11:32ZEdge detection using the Hessian based Frangi Vesselness filterHi every one
I have coloured image (image.jpg) and I want to detect the edges in this image using Hessian based Frangi Vesselness filter. I have downloded this function from this web:
<http://www.mathworks.com.au/matlabcentral/fileexchange/24409-hessian-based-frangi-vesselness-filter>
But I don't know how to apply this function to do edge detection for my image.
can any one help me with the matlab codes for that. Your help is greatly appriciatedMaryhttps://ch.mathworks.com/matlabcentral/profile/authors/2896346tag:ch.mathworks.com,2005:Question/7600512021-03-02T05:22:30Z2021-03-03T06:04:25ZHow can I get slope from DEM data? Hi, I'm undergraduate student from Yonsei University, Seoul. I have a question about MATLAB.
I have a DEM data like this picture.
Each row and column indicates the length of data set(1952X2101), and each value means elevation.
I want to calculate the slope of radom radial degree.
If I put random radial degree like 45 degree(0-90 degree), MATLAB shows slope like 0.08 (in ratio)
How can I make this one?
Thanks for reading. HyoJae Leehttps://ch.mathworks.com/matlabcentral/profile/authors/21523258tag:ch.mathworks.com,2005:Question/7611562021-03-03T04:23:59Z2021-03-03T06:03:56ZChange the position of a field in a structureI want to add a new field to an already existed structure. But as I try to insert it, it goes at the end position. But I want to change its position to the top
Example:
x=
a: 1
b: 2
c: 3
......
now I insert
x.d=4
it shows
x=
a: 1
b: 2
c: 3
.......
d: 4
but I want it to show
x=
d: 4
a: 1
b: 2
c: 3
......Abdulah Al Mubinhttps://ch.mathworks.com/matlabcentral/profile/authors/21475585tag:ch.mathworks.com,2005:Question/7612262021-03-03T06:03:45Z2021-03-03T06:03:45ZHow to find mutual information between successive bands in a hyperspectral image?I have a hyperspectral image of 103 bands and I want to find the mutual information between each and every band. Can someone share the code for the same.Ramya Guttahttps://ch.mathworks.com/matlabcentral/profile/authors/17436835tag:ch.mathworks.com,2005:Question/7611012021-03-03T03:06:19Z2021-03-03T06:00:47ZIntegral Function inside while loop only works for certain values. ArrayValued results in empty volumn vectors.
I am having issues with the integral function only working for certain values of K.
I am looping through an interative summation where I calculate the nth solution of tan(L*z) = -K/h*z. The nth solution is a term in the functions defined by fun and fun2. If the value of K is set to 0.04, the program runs just fine. If I set the value of K to 20, the program throws the error
"Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued' option to
true."
If I set the integral function to 'ArrayValued', true, then the code will run for the first iteration of the while loop, but in the second iteration the integral function will return an empty 0x1 vector.
while deltaW> 0.1 && n<1000
S= double(vpasolve(tan(L*z)== -K/h*z,z, [sol sol+pi/2/L]));
if isempty(S) ==1 %If empty reads false happens when there is a solution
sol = sol+pi/2/L;
S= vpasolve(tan(L*z)== -K/h*z,z, [sol sol+pi/2/L]);
sol=single(S);
end
lambdan=double(S);
sol = lambdan+0.01;
fun = @(x) ((Tinit-(T0 - h*(T0 - Tinf)/(K + h*L).*x))) .* sin(x.*lambdan);
fun2 = @(x) sin(x.*lambdan).^2;
anumerator = integral(fun,0,L);
adenominator = integral(fun2,0,L);
An = anumerator/adenominator;
Wn= An .* sin (lambdan.*x) .* exp(-lambdan.^2.*K.*time);
if n==1
W=Wn;
end
if n>1
deltaW = max(abs(W-Wn));
W=W+Wn;
end
n=n+1;
endGehn Fergusonhttps://ch.mathworks.com/matlabcentral/profile/authors/21486522tag:ch.mathworks.com,2005:Question/1668712014-12-16T05:00:00Z2021-03-03T05:57:17ZHow will running the restoredefaultpath and savepath commands affect my custom paths and how do I back up my custom paths?I setup custom paths from within MATLAB but now need to restore the default path. How does the restoredefaultpath command affect my custom paths and how can I back them up before running it?MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813tag:ch.mathworks.com,2005:Question/7612212021-03-03T05:54:52Z2021-03-03T05:54:52ZSuggest some Tutorial book or pdf to learn Content Based Image and Video Retrieval with Matlabhi, I want to learn CBIR with matlab. Please suggest some Tutorial, Documentation , Pdf etc for Learning this. It would be very helpfull if you suggest some.Thank you in advance:Anuj kumar Sahuhttps://ch.mathworks.com/matlabcentral/profile/authors/21471839tag:ch.mathworks.com,2005:Question/1063412013-11-15T23:49:05Z2021-03-03T05:54:03ZHow to get 'type' of a variable in matlab?Hi,
We declare many types of variables in matlab such as double, string, symbolic etc. How to get type of a variable? Andrewhttps://ch.mathworks.com/matlabcentral/profile/authors/4760308tag:ch.mathworks.com,2005:Question/1654962014-12-04T05:00:00Z2021-03-03T05:54:01ZHow do I install a hardware support package in MATLAB?Where can I find instructions on how to install a hardware support package in MATLAB using the Support Package Installer?MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813tag:ch.mathworks.com,2005:Question/2711772016-03-03T08:04:59Z2021-03-03T05:51:25ZHow to restrict the range ?I want to restrict the output of the arc cosine to be in the range [-1,1], but I want to know if there is built-in Matlab function for this task and if it is possible for example merge @max & @min simultaneoulsy in the function bsxfun to achieve this task.Susan Arnoldhttps://ch.mathworks.com/matlabcentral/profile/authors/7715118tag:ch.mathworks.com,2005:Question/7612162021-03-03T05:49:26Z2021-03-03T05:49:26Zhow to solve this matrix problem?hi to all:
i hope everyone will be fine and doing well, i wan to find the values of x such that when x reaches to 1 the programme should stop, all other values have given in above attached file.
thanks Engineer Batoor khan mummandhttps://ch.mathworks.com/matlabcentral/profile/authors/17655576tag:ch.mathworks.com,2005:Question/1585842014-10-09T04:00:00Z2021-03-03T05:47:29ZImplications of Shellshock bug on Simulink Support Package for Raspberry PiI am using the Simulink Support Package for Raspberry Pi hardware. Is that affected by Shellshock bug?MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813tag:ch.mathworks.com,2005:Question/7599162021-03-02T01:34:44Z2021-03-03T05:46:52ZCan I assign a variable to a number in a matrix from another matrix?Using the matrix that comes from eig(), I would like to assign individual values in it to 3 separate variables, and then plug those into a separate matrix. However, I get an error. How do I do this?
E = eig(A)
E(1,1) = w1;
E(2,1) = w2;
E(3,1) = w3;
ans = [m1*w1^2 0 0;
0 m2*w2^2 0;
0 0 m3*w3^2 0]
Unrecognized function or variable 'w1'.
Error in eigen (line 23)
E(1,1) = w1;Anastasia Zistatsishttps://ch.mathworks.com/matlabcentral/profile/authors/20783629tag:ch.mathworks.com,2005:Question/2766042016-04-01T04:00:00Z2021-03-03T05:46:42ZPrinting Plots Does Not Work in MATLAB R2016aThis simple example works in MATLAB R2015b where I am able to click the print plot icon and successfully print the plot.
y=1:.2:10
z=2*y
figure,plot(y,z)
In R2016a the plot appears as usual - however when I click on the print plot icon I get the following error:
ERROR: Warning: HGUsingMATLABClasses will be removed in a future release. For more information about writing code that works in multiple releases, click here.
> In gobjects
In newplot (line 47)
In error (line 3)
Warning: HGUsingMATLABClasses will be removed in a future release. For more information about writing code that works in multiple releases, click here.
> In gobjects
In newplot (line 48)
In error (line 3)
Also modifying the simple example to include a print command:
y=1:.2:10
z=2*y
figure,plot(y,z)
print('test.pdf','-dpdf');
MATLAB produce this error:
ERROR: Warning: HGUsingMATLABClasses will be removed in a future release. For more information about writing code that works in multiple releases, click here.
> In gobjects
In newplot (line 47)
In generror (line 3)
Warning: HGUsingMATLABClasses will be removed in a future release. For more information about writing code that works in multiple releases, click here.
> In gobjects
In newplot (line 48)
In generror (line 3)
No appropriate method, property, or field 'FillPage' for class
'matlab.graphics.internal.mlprintjob'.
Error in validate (line 174)
if pj.FillPage || pj.BestFit
Error in print (line 81)
pj = validate( pj );
Error in generror (line 4)
print('test.pdf','-dpdf')
I have tried "restoredefaultpath" and I get this error:
ERROR: Error using restoredefaultpath (line 47)
MATLAB could not construct the default path due to missing files. For help, contact your system administrator or MathWorks Technical Support.
Is there a way to fix this?MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813tag:ch.mathworks.com,2005:Question/7545442021-02-24T07:11:24Z2021-03-03T05:46:31ZUnrecognized function or variable 'colorize'.Why can't i use the 'colorize' function despite having the Image Processing Toolbox™ Hyperspectral Imaging Library installed?
ThanksFadhli Ataritahttps://ch.mathworks.com/matlabcentral/profile/authors/15763417tag:ch.mathworks.com,2005:Question/943812013-09-06T17:42:00Z2021-03-03T05:44:25ZWhy does the MATLAB installer fail with an error related to a lxe_win64 or .enc file?When installing MATLAB on my machine I get an error like the following:
The following error was detected while installing lxe_win64:
Missing Entry: lxe_win64_1368859906.enc
OR
"Missing Entry: lxe_common_1384906630.enc
Would you like to retry installing lxe_win64/lxe_common? If you press NO, the installer will exit without completing the installation. More information can be found at C:\Users\<user_name>\AppData\Local\Temp\mathworks_<user_name>.log
MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813tag:ch.mathworks.com,2005:Question/7611662021-03-03T04:32:09Z2021-03-03T05:37:22Zplease help me solve this error on GUIDot indexing is not supported for variables of this type.
Error in DetectDisease_GUI>pushbutton1_Callback (line 44)
axes(handles.axes1);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in DetectDisease_GUI (line 18)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)DetectDisease_GUI('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
function varargout = DetectDisease_GUI(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DetectDisease_GUI_OpeningFcn, ...
'gui_OutputFcn', @DetectDisease_GUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function DetectDisease_GUI_OpeningFcn(hObject, ~, handles, varargin)
handles.output = hObject;
ss = ones(300,400);
axes(handles.axes1);
imshow(ss);
axes(handles.axes2);
imshow(ss);
axes(handles.axes3);
imshow(ss);
guidata(hObject, handles);
function varargout = DetectDisease_GUI_OutputFcn(~, ~, ~)
function pushbutton1_Callback(hObject, ~, handles)
clc
[filename, pathname] = uigetfile({'*.*';'*.bmp';'*.jpg';'*.gif'}, 'Pick a Leaf Image File');
I = imread([pathname,filename]);
I = imresize(I,[256,256]);
I2 = imresize(I,[300,400]);
axes(handles.axes1);
imshow(I2);title('Query Image');
ss = ones(300,400);
axes(handles.axes2);
imshow(ss);
axes(handles.axes3);
imshow(ss);
handles.ImgData1 = I;
guidata(hObject,handles);
function pushbutton3_Callback(hObject, ~, handles)
I3 = handles.ImgData1;
I4 = imadjust(I3,stretchlim(I3));
I5 = imresize(I4,[300,400]);
axes(handles.axes2);
imshow(I5);title(' Contrast Enhanced ');
handles.ImgData2 = I4;
guidata(hObject,handles);
function pushbutton4_Callback(hObject, ~, handles)
I6 = handles.ImgData2;
I = I6;
%% Extract Features
cform = makecform('srgb2lab');
lab_he = applycform(I,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
[cluster_idx , ~] = kmeans(ab,nColors,'distance','sqEuclidean', ...
'Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1,1,3]);
for k = 1:nColors
colors = I;
colors(rgb_label ~= k) = 0;
segmented_images{k} = colors;
end
figure,subplot(2,3,2);imshow(I);title('Original Image'); subplot(2,3,4);imshow(segmented_images{1});title('Cluster 1'); subplot(2,3,5);imshow(segmented_images{2});title('Cluster 2');
subplot(2,3,6);imshow(segmented_images{3});title('Cluster 3');
set(gcf, 'Position', get(0,'Screensize'));
set(gcf, 'name','Segmented by K Means', 'numbertitle','off')
pause(2)
x = inputdlg('Enter the cluster no. containing the ROI only:');
i = str2double(x);
seg_img = segmented_images{i};
if ndims(seg_img) == 3
img = rgb2gray(seg_img);
end
black = im2bw(seg_img,graythresh(seg_img));
m = size(seg_img,1);
n = size(seg_img,2);
zero_image = zeros(m,n);
cc = bwconncomp(seg_img,6);
diseasedata = regionprops(cc,'basic');
A1 = diseasedata.Area;
sprintf('Area of the disease affected region is : %g%',A1);
I_black = im2bw(I,graythresh(I));
kk = bwconncomp(I,6);
leafdata = regionprops(kk,'basic');
A2 = leafdata.Area;
sprintf(' Total leaf area is : %g%',A2);
%Affected_Area = 1-(A1/A2);
Affected_Area = (A1/A2);
if Affected_Area < 0.1
Affected_Area = Affected_Area+0.15;
end
sprintf('Affected Area is: %g%%',(Affected_Area*100))
Affect = Affected_Area*100;
% Create the Gray Level Cooccurance Matrices (GLCMs)
glcms = graycomatrix(img);
% Derive Statistics from GLCM
stats = graycoprops(glcms,'Contrast Correlation Energy Homogeneity');
Contrast = stats.Contrast;
Correlation = stats.Correlation;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
Mean = mean2(seg_img);
Standard_Deviation = std2(seg_img);
Entropy = entropy(seg_img);
RMS = mean2(rms(seg_img));
%Skewness = skewness(img)
Variance = mean2(var(double(seg_img)));
a = sum(double(seg_img(:)));
Smoothness = 1-(1/(1+a));
Kurtosis = kurtosis(double(seg_img(:)));
Skewness = skewness(double(seg_img(:)));
% Inverse Difference Movement
m = size(seg_img,1);
n = size(seg_img,2);
in_diff = 0;
for i = 1:m
for j = 1:n
temp = seg_img(i,j)./(1+(i-j).^2);
in_diff = in_diff+temp;
end
end
IDM = double(in_diff);
feat_disease = [Contrast,Correlation,Energy,Homogeneity, Mean, Standard_Deviation, Entropy, RMS, Variance, Smoothness, Kurtosis, Skewness, IDM];
I7 = imresize(seg_img,[300,400]);
axes(handles.axes3);
imshow(I7);title('Segmented ROI');
%set(handles.edit3,'string',Affect);
set(handles.edit5,'string',Mean);
set(handles.edit6,'string',Standard_Deviation);
set(handles.edit7,'string',Entropy);
set(handles.edit8,'string',RMS);
set(handles.edit9,'string',Variance);
set(handles.edit10,'string',Smoothness);
set(handles.edit11,'string',Kurtosis);
set(handles.edit12,'string',Skewness);
set(handles.edit13,'string',IDM);
set(handles.edit14,'string',Contrast);
set(handles.edit15,'string',Correlation);
set(handles.edit16,'string',Energy);
set(handles.edit17,'string',Homogeneity);
handles.ImgData3 = feat_disease;
handles.ImgData4 = Affect;
% Update GUI
guidata(hObject,handles);
function edit2_Callback(~, ~, ~)
function edit2_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(~, ~, ~)
function edit3_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit4_Callback(~, ~, ~)
function edit4_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, ~, handles)
test = handles.ImgData3;
Affect = handles.ImgData4;
% Load All The Features
load('Training_Data.mat')
% Put the test features into variable 'test'
result = multisvm(Train_Feat,Train_Label,test);
%disp(result);
% Visualize Results
if result == 0
R1 = 'Alternaria Alternata';
set(handles.edit2,'string',R1);
set(handles.edit3,'string',Affect);
helpdlg(' Alternaria Alternata ');
disp(' Alternaria Alternata ');
elseif result == 4
R5 = 'Healthy Leaf';
R6 = 'None';
set(handles.edit2,'string',R5);
set(handles.edit3,'string',R6);
helpdlg(' Healthy Leaf ');
disp('Healthy Leaf ');
end
% Update GUI
guidata(hObject,handles);
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(~, ~, ~)
close all
function edit5_Callback(~, ~, ~)
function edit5_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_Callback(~, ~, ~)
function edit6_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit7_Callback(~, ~, ~)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit7 as text
% str2double(get(hObject,'String')) returns contents of edit7 as a double
% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, ~, ~)
% hObject handle to edit7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit8_Callback(~, ~, ~)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, ~, ~)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit9_Callback(~, ~, ~)
% hObject handle to edit9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit9 as text
% str2double(get(hObject,'String')) returns contents of edit9 as a double
% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, ~, ~)
% hObject handle to edit9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit10_Callback(~, ~, ~)
% hObject handle to edit10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit10 as text
% str2double(get(hObject,'String')) returns contents of edit10 as a double
% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, ~, ~)
% hObject handle to edit10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit11_Callback(~, ~, ~)
function edit11_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit12_Callback(~, ~, ~)
function edit12_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit13_Callback(~, ~, ~)
function edit13_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit14_Callback(~, ~, ~)
function edit14_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit15_Callback(~, ~, ~)
function edit15_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit16_Callback(~, ~, ~)
function edit16_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit17_Callback(~, ~, ~)
function edit17_CreateFcn(hObject, ~, ~)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
krishna vamsi narlahttps://ch.mathworks.com/matlabcentral/profile/authors/19879812tag:ch.mathworks.com,2005:Question/7611412021-03-03T03:59:52Z2021-03-03T05:35:14Zhow to use curve fitting without using curve fitting toolbox?I want to use curve fitting tool in the matlab script without opening the curve fitting toolbox.
I have a data (x,u) and i want to use fiiting in the matlab m.file. I used interplant with linear method as indicated in the following image.
how can i write the code in the M file to do the same done using cftool?
zeinhttps://ch.mathworks.com/matlabcentral/profile/authors/17514856tag:ch.mathworks.com,2005:Question/7612112021-03-03T05:34:08Z2021-03-03T05:34:08ZMATLAB "conv"command valid for both causal and non causal signals?Can we use the built in MATLAB command "conv" for both causal and non causal signals?ABTJhttps://ch.mathworks.com/matlabcentral/profile/authors/13735689tag:ch.mathworks.com,2005:Question/7611212021-03-03T03:31:22Z2021-03-03T05:32:55ZCall mex function using system()?I downloaded a toolbox, which contains a pre-compiled mex file, foo.mexa64.
The calling syntax is a little bit confusing, but it works
system('/home/john/tools/foo.mexa64 param1 param2');
I tried to use
foo(param1, param2)
but I got an error, matlab says 'Invalid MEX-file, ...... cannot dynamically load executable'
It seems that this foo.mexa64 has been compiled to be an executable rather than a mex function. I searched the doc but it did not mention that I can build an executalbe with a suffix .mexa64.Xingwang Yonghttps://ch.mathworks.com/matlabcentral/profile/authors/15183348tag:ch.mathworks.com,2005:Question/7611762021-03-03T05:04:05Z2021-03-03T05:31:52ZHow to fit an exponential curve? error: Dimensions of arrays being concatenated are not consistentHello,
I have an energy plot that I would like to fit an exponential curve to.
I have something like this
numSteps = 5000;
x = 0:1:100;
time = zeros(1,numSteps+1);
ex_data = zeros(length(x),numSteps+1);
ex_data(:,1) = ex;
E_f = zeros(1, numSteps+1);
E_f(1) = 0.5*sum(ex.^2);
for i = 1:numSteps
%some calculations
[ex] = func(..) % ex calculated through some function
time(i+1) = (i)*dt;
E_f(i+1) = 0.5*sum(ex.^2 ) ;
end
%plot
figure(1)
s = fittype('a-b*exp(-c*x)');
f = fit(time, E_f, s, 'StartPoint', [[ones(size(time)), -exp(-time)]\E_f; 1]);
xx = linspace(0,50,250);
plot(time, E_f, 'o', xx, f(xx), 'r-');
grid on
title('Electric Field Energy')
I am trying to fit an exponential to this plot from xlim([ 0 80]) but I am getting the error
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in WeakBeam (line 184)
f = fit(time, E_f, s, 'StartPoint', [[ones(size(time)), -exp(-time)]\E_f; 1]);
I will post the entire code with functions if needed, thank you. Lujain Almarhabihttps://ch.mathworks.com/matlabcentral/profile/authors/12080112tag:ch.mathworks.com,2005:Question/7611812021-03-03T05:07:52Z2021-03-03T05:28:26ZApp designer UIAxes loopHi. I am user app designer and need to designate different locations (for graphing) based on the loop # and a given starting value.
For example, if num= 3 and w = 1, the coding will go:
for i = 1:num
UserPlot = app.UIAxes(i)_w
Scatter(UserPlot, x , y)
end
So, the user plot should have results of: app.UIAxes1_1, app.UIAxes2_1, app.UIAxes3_1 after the loop is complete.
How would i write the "UserPlot = ...." line. Jonathan Moormanhttps://ch.mathworks.com/matlabcentral/profile/authors/11034260tag:ch.mathworks.com,2005:Question/7254222021-01-24T09:30:21Z2021-03-03T05:27:11ZFind An and Bl Unknown Coefficient
Hi guys , Need your help to find this Unknown Coefficient . and coding in matlab for solve integral in summation,
l = 0:20 , m = -20:20 , n = 0 : 20 , C = 10 , b = 0 ,
V = 2/3 , V1 = 2.0001/3 , K = 2*pi ,
"EpsilonN : E(n=0) = 1 and for E(n>=1)=2 ",
a(n) = is fix coefficient - and different with "An".
In Equation 18, the "m" must be added.
An and Bl we do need to find .
Regards.
Arash Shahpasandhttps://ch.mathworks.com/matlabcentral/profile/authors/13986917tag:ch.mathworks.com,2005:Question/7612062021-03-03T05:27:05Z2021-03-03T05:27:05ZEquation with summation - Discrete time
I want to plot this x(tk) with respect to time t
How do I implement this using MATLAB?Sahil Deshpandehttps://ch.mathworks.com/matlabcentral/profile/authors/21076953tag:ch.mathworks.com,2005:Question/7612012021-03-03T05:26:06Z2021-03-03T05:26:06Zhow to solve non linear differential equations dx(t)/dt=y(t)
dt(t)/dt=-(1/r+g+a+b|x(t)|)y(t)/c-x(t)/(lc)
t=-0.05:0.01:0.05
r = 1430;
a = -0.0683;
b = 0.0676;
c = 36*10^-9;
g = -0.0676;
l=27
i want to plot phase portrait of (x(t),y(t)) and plots for (t,x(t)),(t,y(t))nune pratyushahttps://ch.mathworks.com/matlabcentral/profile/authors/14783252tag:ch.mathworks.com,2005:Question/7311982021-01-30T13:34:43Z2021-03-03T05:25:49ZHow to calculation this integral ?
L0 = 0:20
M0 = -20:20
N0 = 0:20
C = 10 ,
b = 0 ,
V = 2/3 ,
V1 = 2.0001/3 ,
K = 2*pi ,
"EpsilonN : E(n=0) = 1 and for E(n>=1)=2 ",
EpsilonN = [1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2]
%-------------------------------------------------------------------------------------------------------
for L1 = 0:length(L0)
for M1 = 0:length(M0)
for N1 = 0:length(N0)
if (L1/V1)+M1 ~= (N1/V0) %SA1 ~= abs(SA2)
Clmn = (EpsilonN/2*V0*pi)*besselj(M1,K*B)*((sin(((L1/V1)+M1+(N1/V0))*V0*pi)/(L1/V1)+M1+(N1/V0))+...
(sin(((L1/V1)+M1-(N1/V0))*V0*pi)/(L1/V1)+M1-(N1/V0))); %<part 1>
else N1 ~= 0 %n ~= 0 ,
Clmn = (EpsilonN/2)*besselj(M1,K*B) ; %<part 3>
if (L1/V1)+M1 == (N1/V0) %SA1 == SA2 ,
Clmn = EpsilonN*besselj(M1,K*B); %<part 2>
end
end
end
end
end
ClmnArash Shahpasandhttps://ch.mathworks.com/matlabcentral/profile/authors/13986917tag:ch.mathworks.com,2005:Question/7611962021-03-03T05:24:38Z2021-03-03T05:24:38ZTo combine the segmentation processHi, I have the code to read multiple images at the same time and then proceed with the process of removing the image background. Then the code for the Canny process, and the code to change the image from grayscale to green channel, then CLAHE. I want to combine this code so that it will be composed of grayscale, green channel, CLAHE, remove background, and canny.
Can anyone help me?
Code for grayscale until CLAHE and Canny
citra=imresize(imread('image.jpg'),1);
figure, fig1=imshow(citra);
%change to grayscale
grayimg = rgb2gray(citra);
figure, fig2=imshow(grayimg);
%change to green channel
green_channel = citra(:,:,2);
figure, fig3=imshow(green_channel);
%change to CLAHE (Contrast Limited Adaptive Histogram Equalization)
CLAHE = adapthisteq(green_channel);
figure, fig4=imshow(CLAHE);
ER = edge(CLAHE, 'canny');
EG = edge(CLAHE, 'canny');
EB = edge(CLAHE, 'canny');
anyedge = ER | EG | EB;
figure, fig5=imshow(anyedge)
size(fig5)
2. Code For read multiple images at the same time and then proceed with the process of removing the image background
image_folder = 'F:\kuliah\semester6\TA2\mencoba';
outfolder = 'F:\kuliah\semester6\TA2\mencoba\hasil';
if ~isdir(outfolder); mkdir(outfolder); end
load mri %I presume it has the variable map in it
files = dir(fullfile(image_folder, '*.jpg'));
for iFiles = 1:numel(files)
thisfilename = fullfile(files(iFiles).folder,files(iFiles).name);
[~, basename, ext] = fileparts(image_folder);
citra = imread(thisfilename);
V = squeeze(citra);
fprintf('processing %s\n', basename);
fig = figure;
citra3 = montage(reshape(V,size(citra)), map, 'Indices', 3);
outfile = fullfile(outfolder, sprintf('%s-coba-%03d.jpg', basename, iFiles));
saveas(citra3, outfile);
endFrisda Sianiparhttps://ch.mathworks.com/matlabcentral/profile/authors/21534709tag:ch.mathworks.com,2005:Question/7611512021-03-03T04:04:16Z2021-03-03T05:22:05ZUSB-C communicationHi all, just wonder, if I want to read data out of a certain device while connecting through usb-c cable how do I do so? Is it the same as using serial port for normal usb connection? but from my device manager, I didnt see any usb-c port when I connect it to my laptop. please helpWei Wei Ganhttps://ch.mathworks.com/matlabcentral/profile/authors/19744806tag:ch.mathworks.com,2005:Question/1533692014-09-04T04:00:00Z2021-03-03T05:21:49ZHow can I integrate MATLAB Production Server with an Oracle Database?In my Oracle Database I have defined a TRIGGER AFTER INSERT on MYTABLE1. In this trigger I want to do some calculations on the inserted data and then insert the result into MYTABLE2. To perform these calculations I want to make use of my MATLAB Code which was deployed to an MATLAB Production Server (MPS). Is this possible?MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813tag:ch.mathworks.com,2005:Question/3173612016-12-18T17:34:59Z2021-03-03T05:20:47ZIN remote sensing seven spectral bands are exists in multi spectral images, how to make seven spectral bands of images into one false color image in matlab not in ERDAS what function in matlab add these 7 spectral bands in to one false color imagevenkata prasad sistahttps://ch.mathworks.com/matlabcentral/profile/authors/4757334tag:ch.mathworks.com,2005:Question/7030822020-12-27T06:06:02Z2021-03-03T05:19:23Zhow to plot this for different types of loads in simply supported beam?%% Eaxmple 1
Name1 = 'Sample Problem 5_2';
% Length and Supports
LengthSupport1 = [16,16];
% Concetrated Loads
F1_1 = {'CF',-10,11};
% Turning loads, Torque
T1_1 = {'M',-20,11};
% Distributed Loads
D1_1 = {'DF',-3,[0,8]};
% Call the function
sfbm (Name1,LengthSupport1,F1_1,T1_1,D1_1);
the error i am getting:
Error in ass4 (line 12)
sfbm (Name1,LengthSupport1,F1_1,T1_1,D1_1);Siddhant Dashttps://ch.mathworks.com/matlabcentral/profile/authors/20703404tag:ch.mathworks.com,2005:Question/7525192021-02-22T11:23:57Z2021-03-03T05:16:02ZCreating Sphere using Cuboids of varying size I want to make a sphere using cuboids. The radius of the sphere is 60 mm and I want to divide this whole radius in 12 units so that a single unit has a fixed size of 5mm (a single unit represents a cuboid of size, 5 mm x 5mm x 5mm). Each cuboid unit has its center fixed at some point along the radius. Now, within this unit, the size of the cuboid is varied according to value of b having the same center as previous cuboid (but the current size will be less because of varying cuboid size so that no overlapping between two cuboids). The size of the cuboid (b) is governed by the equation as;
b=5.698-16457*exp(-a/0.11)-8.373*exp(-a/1.092),
where the values of a is varied from 1 to 2 with a step of 0.1. I need a MATLAB code for this problem statement. What appraoch should be used? Thanks in advance.RAHUL JAISWALhttps://ch.mathworks.com/matlabcentral/profile/authors/14306814tag:ch.mathworks.com,2005:Question/7611862021-03-03T05:11:11Z2021-03-03T05:11:11ZHow Distribution filter app chooses options for curve fit?I am trying to apply exponential fit to my data, but no option is showing up for exponential fit.
For same script and data set, its showing exponential fit but with one additional scaling its not showwing up same fit option. (Obviously after scaling also distribution still similar shape)
Can anybody tell how distribution filter app gives options for fit and how can I fit a specific curve which is not coming up in the app options?Vijay Joshihttps://ch.mathworks.com/matlabcentral/profile/authors/15895906tag:ch.mathworks.com,2005:Question/7573792021-02-26T19:56:14Z2021-03-03T05:08:16ZIncremental Learning Intrusion Detection System for Fog EnvironmentAfter Greetings.
Hope this finds you in best of your health and happiness.
My name is Aftab Alam and I am a research scholar.
I want to have some consultancy for my topic.
I want to design an Intrusion Detection System for the Fog Environment.
I want to do the simulation through MATLAB.
Could you please guide me from where to start and what things should be known to be in MATLAB?
Looking forward to hear soon from you.
With Respects and Regards
Aftab AlamAftab Alamhttps://ch.mathworks.com/matlabcentral/profile/authors/21541197tag:ch.mathworks.com,2005:Question/7608012021-03-02T19:02:43Z2021-03-03T05:06:20ZProcessing Multiple EMG filesI have multiple files of raw EMG data of different muscles that needs to be linear enveopled. I know how to do that and have made code for it but I was wonderig if there would be a way to run the code on multiple files to save some time. I know that a for loop of some sorts could be used but I do not understand how to create one for files instead of vectors. Is there any way to do this?
ex. the files can be found in 'C:, User, User1, Downloads, S02, S2_T3data, Proceessed_EMG, Cond_EMG "
the files are named : SCM_L, SCM_R, UTR_L, UTR_R
Thanks in advanceRyan Chhibahttps://ch.mathworks.com/matlabcentral/profile/authors/21426145tag:ch.mathworks.com,2005:Question/1532082014-09-02T04:00:00Z2021-03-03T05:04:48ZHow can I make the contour plot of an "sfit" object resemble the plot generated by the "contour" command in MATLAB R2013b?I am making a surface fit using the "fit" function and using it to generate a contour plot with the following code:
load franke
sf = fit([x y], z, 'poly23');
plot(sf, 'Style', 'Contour');
This generates the following plot:
However, the plot that is generated looks different from what I would get by using the "contour" function. How can I make it look the same?
MathWorks Support Teamhttps://ch.mathworks.com/matlabcentral/profile/authors/4622813tag:ch.mathworks.com,2005:Question/7604762021-03-02T14:27:18Z2021-03-03T05:03:19ZHow to Find MSE and PSNR ?Please help me, an error occurred when I was calculating the score of MSE and PSNR
“Error using -
Integers can only be combined with integers of the same class, or scalar doubles.”
I use an MSE and PSNR function like the following:
function [nilaiMSE, nilaiPSNR] = MSE_PSNR(citra_Prepro,citra_Process);
%MSE
[m, n] = size(citra_Process);
nilaiMSE = sum(sum(citra_Prepro - (citra_Process .^2))/(m*n));
%PSNR
nilaiPSNR = 10*log10(255*255/(nilaiMSE));
end
And I used to look for the following value:
citra_Prepro= getimage(handles.axes_Preview);
citra_Process= getimage(handles.axes_IHPF);
[nilaiMSE, nilaiPSNR]= MSE_PSNR(citra_Prepro,citra_Process);
set(handles.MSE_IHPF,'String', nilaiMSE);
set(handles.PSNR_IHPF,'String', nilaiPSNR);
where my "citra_Prepro" variables gets from histogram equalization and my "citra_Process" variables gets from Ideal High Pass Filter.Akbar Ramadhanhttps://ch.mathworks.com/matlabcentral/profile/authors/21659614tag:ch.mathworks.com,2005:Question/3455702017-06-20T18:29:38Z2021-03-03T04:51:53Zxlswrite too large imputHi everybody.
I' trying to save a very large cell matrix (1 393 120 x 15) to a xlsx, but xlswrite returns:
'The specified data range is invalid or too large to write to the specified file format. Try writing to an XLSX file
and use Excel A1 notation for the range argument, for example, ‘A1:D4’.'
Does anybody knows how could I do this?
Thank you!
PS: my code is
xlswrite('C:\Users\***\CompresorCompleto.xlsx',DatosTot.raw);
where *** are the full path (and it's ok, I check it) and DatosTot.raw is the matrix I want to writePablo Gomez Gómez Gonzalohttps://ch.mathworks.com/matlabcentral/profile/authors/7780558tag:ch.mathworks.com,2005:Question/7567792021-02-26T08:50:50Z2021-03-03T04:51:25ZSetup a Simulink model to work only with a license fileHi,
I would like to setup a Simulink model to work only in presence of a license file.
This license file shall have an expiry date, such that the Simulink model does not work when the license is expired.
Is there a way to implement such a feature in Simulink?
Thanks.
Best regardsAlessandro Massimo Giordanohttps://ch.mathworks.com/matlabcentral/profile/authors/10530125tag:ch.mathworks.com,2005:Question/7611712021-03-03T04:50:27Z2021-03-03T04:50:58Z2D Fourier Transform of sine wave: f(x,t)=2sin(2x-3t). Need to normalize axis and amplitude such that peaks occur at k=2 and f= 3, I'm getting unnormalized plots without proper peaks.clc
f = 3; %frequency
k= 2;
Fs = 80; %sampling rate
Xs = 90;
Ts = 1/Fs; %sampling time interval
Xs = 1/Xs;
t = 0:Ts:1-Ts; %sampling period
x = 0:Xs:1-Xs;
n = length(t); %number of samples
[X,T] = meshgrid(x,t);
y = 2*sin(2*pi*k*X-2*pi*f*T); %the sine curve
grid
A = fft2(y)/length(y); %take the fft of our sin wave, y(t)
B=(abs(A).^2);
surf(B);
xlabel('Non-normalized w')
ylabel('Non-Normalized k')
title('Peaks test')
grid
PShttps://ch.mathworks.com/matlabcentral/profile/authors/21443789tag:ch.mathworks.com,2005:Question/7609462021-03-02T21:43:20Z2021-03-03T04:45:49ZWhat should I do if the brightness of backgroud is very close to foreground?Hi,
I have some images that I want to segment. However, The the brightness of backgroud is very close to foreground in my images.
Here is a example,
The red circled object is what I want. But after trying different methods, this is what I got
Is there any suggestions to get a better result? These segmented images are used to be mask for 3D segmentation by using ‘activecontour’. Other images have similar problem. And as you can imagine, The 3D structure is much larger than what I want.
Thanks!Dongyu Lianghttps://ch.mathworks.com/matlabcentral/profile/authors/15487013tag:ch.mathworks.com,2005:Question/7609812021-03-02T23:13:45Z2021-03-03T04:44:01Zsolving a system of 2nd order 2 ODE: output vector length not matching the initial condition vector lengthI am trying to solve a 2nd order system of 2 ODEs using the ODE45. the variables to be solved are V_1 and V_6.
the output vetor y = [V_1 ; V_1' ; V_6 ;V_6'] as I defined has the length of 4, and it matches the definition of the system of ODEs
the length of the initial condition vector is 4, and it matches the definition of the system of the 2 ODEs
but I get this error:
"LINEAR_ODE returns a vector of length 2, but the length of initial conditions vector is 4. The vector returned by
LINEAR_ODE and the initial conditions vector must have the same number of elements."
the ODE equations are pretty complicated but correspond to the equations of a coupled two LC resonators. I checked my code pretty much but going crazy.
I am following the same approch as is in this question (https://www.mathworks.com/matlabcentral/answers/491409-how-to-solve-system-of-2nd-order-differential-equations-using-ode45), and the code works with no error !
Thank you so much !
TimeScale= 10*1E-10;
TimeStep= 1 * 1E-15;
tspan = [0:TimeStep: TimeScale];
y0 = [0; 0; 0;0];
% y = [V_1; V_1'; V_6 ;V_6']
%y(1)=V_1 y(2)=V_1' y(3)=V_6 y(4)=V_6'
[t, y]= ode45(@Linear_ODE, tspan, y0);
function dydt=Linear_ODE(t,y)
h = 6.62607015 * 1E-34 ; % [J s]
e=1.60217662 * 1E-19; %[C] % elementary charge(C)
K_J= (2*e*2*pi)/h ;%2e/h_bar
C_1 = 0.3e-12;
L_5 = 10.0e-9;
L_J = 2*L_5;
L_3 = L_J;
M_4 = 100e-12;
C_6 = 0.3e-12;
tildeL_3 = L_3-M_4;
tildeL_5 = L_5-M_4;
V_0 = 1e-6;
R_s=50;
Ic_0= 25e-9;
w= 2.9e09;
Alpha= tildeL_3 + M_4;
Beta = tildeL_5 + M_4;
TimeStep= 1 * 1E-15;
dydt= [y(2); -1/(R_s*C_1)*y(2)-(1 + Alpha * 1/L_J)*1/(Alpha*C_1) * y(1) + M_4*C_6/(C_1*Alpha) * diff(y(4))/TimeStep-V_0*w*sin(w*t)/(R_s*C_1) ; y(4) ; M_4*C_1/(C_6*Beta)* diff(y(2))/TimeStep+ M_4/(R_s*C_6*Beta)* y(2)+ M_4*1/(C_6*Beta)* 1/L_J * y(1)+y(3)/(C_6*Beta)+ M_4/(R_s*C_6*Beta)*V_0*w*cos(w*t)];
end
yosri ayadihttps://ch.mathworks.com/matlabcentral/profile/authors/16787577tag:ch.mathworks.com,2005:Question/7605712021-03-02T15:56:27Z2021-03-03T04:43:23ZHow do I declare varibles whose outputs are expected from Matlab simply without so many rules, like for example in c++?[Below is my code its meant to do as follows, as long as k<NoS, it shall form Equations that at the end of the day are equivalent to k =NoS. Afterwards, it should sum them up, and do fminsearch for Xcal Ycal Zcal and t0. My problem is however I declare the variables Xcal,Ycal,Zcal and t0 whether using syms Xcal, Ycal,Zcal, t0 or Xcal=(1,1,'double') ...etc. Matlab always displays the following "error Conversion to double from function_handle is not possible.". I am new to matlab, but I think there are just too many rules about multiplication and division. Whichever way I do it, there are always errors chiefly '.*' is not allowed for cell variables or sometimes '*' operand is not allowed for this kind of variable and so on and so forth. I've written a separate function on a different.m.file which can run, but I am just hoping to keep things simple and operate within one script, using an anonymous function as indicated. Also I am not very farmiliar with how to call functions or variables across scripts. I am not sure if what I am doing is correct or could someone let me know what I am not doing right thanks]
.....
while k<NoS;
k=1:NoS;
Xcal={};
Ycal={};
Zcal={};
t0={};
eqn=zeros(1,NoS);
eqn(k)=........
@(Xcal,Ycal,Zcal,t0)(sqrt(xj*xj-2*xj*Xcal+Xcal*Xcal+yj*yj-2*yj*Ycal+Ycal*Ycal+zj*zj-2*zj*Zcal+Zcal*Zcal)-c*tj+c*t0)
x0=[500,1000,50,5];
s2=sum(eqn(k));
soln =fminsearch(s2,x0)
break;
end
.....Alphonce Owayohttps://ch.mathworks.com/matlabcentral/profile/authors/13635820tag:ch.mathworks.com,2005:Question/7611112021-03-03T03:07:43Z2021-03-03T04:43:12ZReaction kinetics parameter determinationHi, I am new to MATLAB and I have a series of data points to fit and then calculate the rate constants.
here are the equations:
dcdt(1)=-k(1)*c(1)-k(2)*c(1)-k(3)*c(1)
dcdt(2)=k(2)*c(1)-k(6)*c(2)-k(9)*c(2)
dcdt(3)=k(3)*c(1)-k(5)*c(4)-k(7)*c(6)
dcdt(4)=k(1)*c(1)-k(4)*c(4)-k(5)*c(4)
dcdt(5)=k(6)*c(2)+k(4)*c(4)-k(10)*c(5)
dcdt(6)=k(7)*c(3)-k(8)*c(6)
dcdt(7)=k(8)*c(6)+k(9)*c(2)+k(10)*c(5)-k(11)*c(8)-k(12)*c(9)
dcdt(8)=k(11)*c(7)
dcdt(9)=k(12)*c(8)
and the data:
Time=[0 2 4 10 15 25 40]
c= [100 0 0 0 0 0 0
0 4 37 15 5 4 2
0 10 20 8 4 0.2 0.1
0 5 10 16 4 2 1
0 4 5 11 5 4 3
0 5 6 5 1 0.1 0.04
0 6 12 32 64 44 31
0 0.0071 0.06 0.14 0.3000 3.8500 7.4440
0 0 0 0.0340 0.340 0.5000 0.630]
I would really appreciate the help! Thanks in advanceiPandahttps://ch.mathworks.com/matlabcentral/profile/authors/20411535tag:ch.mathworks.com,2005:Question/7611612021-03-03T04:30:06Z2021-03-03T04:30:06ZHi i am solving bvp4c below is my code getting errors help me out
function Mvrh
global n Re p Pr Ec Nr Tw Nu Cp r w E z1 z2 p1 p2;
infinity =4;
We=1;Cp=0.5;n=2.5;Re=1;Pr=6.2;Ec=0.1;Tw=1;Nr=0.2;r=1.6;E=0.001;
Rav=[0 0.02 0.04];
for i = 1:3
E= Rav(i);
h1=0.0;
lines = {'B-','m-','g-'};
solinit = bvpinit(linspace(0,infinity),[0 E 1 1 0]);
sol = bvp4c(@shootode,@shootbc,solinit);
eta = sol.x;
f = sol.y;
% --------------------------------------------------------------------
figure(3)
plot(eta,f(4,:),lines{i},'linewidth',2.5);
xlabel('\bf \eta');
ylabel('\bf Nu'' (\eta)');
legend('\bf Phi1=Phi2=0','\bf Phi1= 0.04', '\bf Phi2=0 ','\bf Phi1=Phi2= 0.04 ');
hold on
end
% --------------------------------------------------------------------------
function dydx = shootode(eta,f)
%EX5OfE ODE function for Example 5 of the BVP tutorial.
global n p2 p1 z1 z2 Re Pr Nu c Cp r w E ;
dydx = [ f(2)
f(3)
(-1/n((1-p2)*((1-p1)+(z1*3970)/(997.1))+(z2*8933)/(997.1))*Re(f(1)*f(3)-f(2)*f(2)+1)+f(3))
f(7)
(-1/n(Pr((1-p2)*(1-p1+p1(3970*765)/(997.1*4179))+P2(8933*385)/(997.1*4179))/(400+2*0.613-2*p2(0.613-400)*40+2*3-2*p1(3-40))/(400+2*0.613+p2(0.613-400)*40+2*3+p1(3-40))*Re*f(1)*f(5)+f(5)))
];
% --------------------------------------------------------------------------
function res = shootbc(fa,fb)
global E Pr L A Re Nu
res = [ fa(1)
fa(2)-E
fa(4)-1
fb(2)-1
fb(4)
];
Manoj Kumar C Nhttps://ch.mathworks.com/matlabcentral/profile/authors/16360497tag:ch.mathworks.com,2005:Question/7609662021-03-02T22:45:21Z2021-03-03T04:29:39ZIteration of Ideal Gas LawHi,
How can I do the iteration for the follwoing Ideal Gas Law? I would like to use the Vn and get the Pn value and compare the Ln value to the L. When Ln and L are very close, it will stop the iteration. I would really appreciate your help.
P=101325;
R=8.314;
r=20*10^-6;
L=117*10^-6;
V=pi*r^2*L;
T=300;
n=(P*V)/(R*T);
% Iteration should start from here
Tn=300+273;
Pn=(n/V)*R*Tn;
stress=Pn;
E=69.22*10^9;
S=stress/E;
dL=S*L;
Ln=L+dL;
Vn=pi*r^2*Ln;Sohel Ranahttps://ch.mathworks.com/matlabcentral/profile/authors/13777906