https://cn.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-02-19T08:01:27Ztag:cn.mathworks.com,2005:Question/3833912018-02-18T20:18:24Z2018-02-19T08:01:27ZHow do I fit an exponential equation to raw data<p>I have been given raw data from a hurricane with the x component, radius, x=59:803 and Y component, pressure, data varying from around 990 to 1020. I have an equaiton y=exp(-A/(x^B)) and want to find coefficients A and B from the raw data. I did try applying fit and to no avail. I'm unfamiliar with these functions so perhaps I was using them incorrectly.</p><p>I hope you can help, Thanks.</p><p>PH</p>Pierce Harthttps://cn.mathworks.com/matlabcentral/profile/authors/10539375-pierce-harttag:cn.mathworks.com,2005:Question/3834552018-02-19T07:59:58Z2018-02-19T07:59:58ZNeed to insert following<p>i m trying to insert the median and averaging filter in my code but it giving me errors ,as i am a beginner in matlab it is taking a lot of time ,i have very limited time for this project,someone can please insert that code in my existing code.and need the corrupt pixel nos for both median & average filter.In my existing code it is calculating the corrupt no of pixels.My project is SR using Adaptive Wiener filter and compare it with median and average filter and show adaptive wiener filter is better than other two.</p>Komal Gaikwadhttps://cn.mathworks.com/matlabcentral/profile/authors/8607151-komal-gaikwadtag:cn.mathworks.com,2005:Question/3834472018-02-19T07:06:30Z2018-02-19T07:57:21ZCombine multiple if statements for something more compact<p>Friends,</p><p>I'm trying to refine my code.It works fine but I have four if conditions which I want to make more efficient. Is there an alternative way to do it?</p><pre class="language-matlab">i=1;
while (VMPH<=60)
% Vehicle speed
t(i+1) = t(i)+delt;
Vmps(i+1) = Vmps(i)+((delt*(Facc(i)))/Vm);
VMPH(i+1) = Vmps(i+1)/0.44704;
% Vehicle forces
Fr(i+1) = Fr(1);
Fd(i+1) = 0.5*Af*Cd*(Vmps(i+1))^2;
% Speed conditions
ig(i+1) = 3.78;
N(i+1) = Vmps(i+1)*io*ig(i+1)*60/(pi*Dt);
if N(i+1) > 2150
ig(i+1) = 2.06;
N(i+1) = Vmps(i+1)*io*ig(i+1)*60/(pi*Dt);
end
if N(i+1) > 2150
ig(i+1) = 1.58;
N(i+1) = Vmps(i+1)*io*ig(i+1)*60/(pi*Dt);
end
if N(i+1) > 2150
ig(i+1) = 1.21;
N(i+1) = Vmps(i+1)*io*ig(i+1)*60/(pi*Dt);
end
if N(i+1) > 2150
ig(i+1) = 0.82;
N(i+1) = Vmps(i+1)*io*ig(i+1)*60/(pi*Dt);
end
</pre><pre> % Power and performance
Tao_b(i+1) = interp1(Speed,Torque,N(i+1));
Tao_w(i+1)= Tao_b(i+1)*io*ig(i+1)*etadrive;
Ft(i+1) = Tao_w(i+1)/Dt*2;
Pb(i+1) = 2*pi*Tao_b(i+1)*N(i+1)/60;
% Acceleration force
Facc(i+1) = Ft(i+1)-Fd(i+1)-Fr(i+1);
i=i+1;
end</pre><p>Thank You!</p>DIPhttps://cn.mathworks.com/matlabcentral/profile/authors/7881208-diptag:cn.mathworks.com,2005:Question/3823922018-02-13T12:09:51Z2018-02-19T07:55:51ZQuestions on errors in GUIDE<p><b>EDITED</b> Hi there can someone help me to decipher the problem with my program, I have been receiving these error messages when i input data into my uitable and clicking the push button to run my code 'compare'. My code is as follows and the error message is attached behind it.</p><pre class="language-matlab">>> function Sample2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Sample2 (see VARARGIN)
% Choose default command line output for Sample2
handles.output = hObject;
storedvals = zeros(1,4);
% Update handles structure
guidata(hObject, handles);
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
storedvals = handles.storedvals;
x = 0;
tableData = get(handles.uitable1, 'data');
compare(storedvals(1),storedvals(3));
if flag == 1
x = 'P1 Complies with A, B and C';
end
if flag == 2
x = 'P1 Complies with C and B';
end
if flag == 3
x = 'P1 Complies with A and C';
end
if flag == 4
x = 'P1 Complies with A';
end
if flag == 5
x = 'P1 Complies with B and C';
end
if flag == 6
x = 'P1 Complies with C';
end
if flag == 7
x = 'P1 Complies with C';
end
if flag == 8
x = 'Complies with None';
end
if flag == 9
x = 'P2 Complies with A, B and C';
end
if flag == 10
x = 'P2 Complies with A and B';
end
if flag == 11
x = 'P2 Complies A and C';
end
if flag == 12
x = 'P2 Complies A';
end
if flag == 13
x = 'P2 Complies with B and C';
end
if flag == 14
x = 'P2 Complies with C';
end
if flag == 15
x = 'P2 Complies with C';
end
if flag == 16
x = 'Complies with None';
end
set(handles.uitable1, 'Data', x)
% --- Executes when entered data in editable cell(s) in uitable1.
function uitable1_CellEditCallback(hObject, eventdata, handles)
% hObject handle to uitable1 (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
data = get(hObject, 'data');
indices = eventdata.Indices;
r = indices(:,1);
c = indices(:,2);
linear_index = sub2ind(size(data),r,c);
storedvals(linear_index) = data(linear_index);
handles.storedvals = storedvals;
guidata(hObject, handles);
</pre><pre class="language-matlab">>> Sample2
Undefined operator '==' for input arguments of type 'cell'.
Error in compare (line 3)
if Proc==1
Error in Sample2>pushbutton1_Callback (line 112)
compare(storedvals(1),storedvals(3));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Sample2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Sample2('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
</pre>Darren Kohhttps://cn.mathworks.com/matlabcentral/profile/authors/11146807-darren-kohtag:cn.mathworks.com,2005:Question/3834382018-02-19T06:03:04Z2018-02-19T07:55:48ZAdding rows and column to existing inter dependency matrix<p>Hi, how to change the below mentioned 'A' matrix to 'AA' matrix by adding a row and column of 'CR' with the exact values for 'CR' as mention below. For 'CR' all the values in the row from CR to E221 will have 0 and in the column, CR will be zero and E1 to E221 will be 1. I want that string 'CR' also need to be added to the existing headings of E1 to E221 in the row and column wise.
I have also attached my code for A matrix and the new AA matrix should be an extension of this code.</p><img src = "/matlabcentral/answers/uploaded_files/105288/Matrix1.JPG"><pre> nm= cellstr(reshape((string({'E','R','E','S','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','E','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR','SR',}) + ([101,1,106,1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] + (0:4)'))',[],1))
N = zeros(44);
N(2:end,1)= 1
N(3:end,2)= 1
N(4,3)= 1
N(5:end,4)= 1
N(25,5)= 1;N(26,6)= 1;N(27,7)= 1;N(28,8)= 1;N(29,9)= 1;N(30,10)= 1;N(31,11)= 1;N(32,12)= 1;N(33,13)= 1;N(34,14)= 1;N(35,15)= 1;N(36,16)= 1;N(37,17)= 1;N(38,18)= 1;N(39,19)= 1;N(40,20)= 1;N(41,21)= 1;N(42,22)= 1;N(43,23)= 1;N(44,24)= 1;
N1=N;
T= repmat({N1},1,5)
A= [{nan},nm';nm,num2cell(blkdiag(T{:}))]</pre>Santhosh Chandrasekarhttps://cn.mathworks.com/matlabcentral/profile/authors/10517346-santhosh-chandrasekartag:cn.mathworks.com,2005:Question/3834542018-02-19T07:54:26Z2018-02-19T07:54:58Zrtp struct does not contain some of the inline parameters<p>Hi all,
I am trying to configure my rapid accelerator model so that I can run it in a loop. However, when I checked inline parameters and select my workspace variables, after using rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget function I cannot see some of them in the rtp structure. Then I isolated those 2 variables, let them be the only inlined parameters then rebuilt again and result is same, rtp.parameters structure is empty. Since I do not guess what is wrong, I cannot elaborate on the issue more hoping that you guys can guide me to solve the problem. With your questions I can provide you with the additional information as well. Running on R2014b.</p>Yigit Sahinhttps://cn.mathworks.com/matlabcentral/profile/authors/10662001-yigit-sahintag:cn.mathworks.com,2005:Question/3774632018-01-16T17:54:50Z2018-02-19T07:51:12ZImage Acquisition Toobox - Webcam Parameters<p>Dear,
I am using Image Acquisition Toobox for a Webcam interface but I only can access limited number of parameters as below. May I ask how can I access all parameters of a Webcam ?</p><pre> Cam1 = webcam(1)
Cam1 =
webcam with properties:
Name: 'Stereo Vision 1'
Resolution: '1280x720'
AvailableResolutions: {1×8 cell}
>></pre><p>Thank you
SK</p>Seungkook Junhttps://cn.mathworks.com/matlabcentral/profile/authors/11012267-seungkook-juntag:cn.mathworks.com,2005:Question/3828322018-02-15T08:59:36Z2018-02-19T07:50:07ZHi i have following code which shows some error how i solve it plzz help <pre class="language-matlab">clear all
clc
syms t x y
</pre><pre class="language-matlab">%points to define the bezier curve
Px = [10 50 60 70];
Py = [30 60 0 20];
</pre><pre class="language-matlab">%equation of bezier curve
</pre><pre class="language-matlab">Pxx = Px(1)*(1-t).^3 + 3*Px(2)*t.*(1-t).^2 + 3*Px(3)*(1-t).*t.^2 + Px(4)*t.^3;
Pyy = Py(1)*(1-t).^3 + 3*Py(2)*t.*(1-t).^2 + 3*Py(3)*(1-t).*t.^2 + Py(4)*t.^3;
Pxd = diff(Pxx);
Pyd = diff(Pyy);
</pre><pre class="language-matlab">%evaluating points of bezier curve
t=0:0.1:1;
Pxx = Px(1)*(1-t).^3 + 3*Px(2)*t.*(1-t).^2 + 3*Px(3)*(1-t).*t.^2 + Px(4)*t.^3;
Pyy = Py(1)*(1-t).^3 + 3*Py(2)*t.*(1-t).^2 + 3*Py(3)*(1-t).*t.^2 + Py(4)*t.^3;
</pre><pre class="language-matlab">%calculating slope of normal at any point
X = subs(Pxd,t);
Y = subs(Pyd,t);
M = -(X./Y);
</pre><pre class="language-matlab">%offset distance (radius of tool/2)
D = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2];
</pre><pre class="language-matlab">%unit vector in direction of normal
R = sqrt(1+(M.^2));
</pre><pre class="language-matlab">%coordinates of pt A
Xa = Pxx+(D./R);
Ya = Pyy+((D.*M)./R);
</pre><pre class="language-matlab">%coordinates of point C (centre of circle)
Xc = Pxx+(-D./R);
Yc = Pyy+((-D.*M)./R);
</pre><pre class="language-matlab">%evaluating the intersection circle and line from above point to next point
for t=0:1:10
[L] = solve(((x - Xc)).^2) +(((y - Yc)).^2)-16, (y - Pyy(t))-(((Pyy(t+1)-Pyy(t))./(Pxx(t+1)-Pxx(t))).*(x - Pxx(t)));
Lx = L.x;
Ly = L.y;
</pre><pre class="language-matlab">%coordinates of point B
Xb = Lx;
Yb = Ly;
</pre><pre class="language-matlab">%slopes of lines from C to B and from C to A
M1 = (Yb-Yc)/(Xb-Xc);
M2 = (Ya-Yc)/(Xa-Xc);
</pre><pre class="language-matlab">%Angle of above lines
Theta(t) = atand(double(M1));
Theta(t+1) = atand(double(M2));
</pre><pre class="language-matlab">%cutter engagement angle
Alpha = Theta(t+1)-Theta(t);
end
</pre>dwivedi shriprakashhttps://cn.mathworks.com/matlabcentral/profile/authors/10684270-dwivedi-shriprakashtag:cn.mathworks.com,2005:Question/3834082018-02-19T00:28:27Z2018-02-19T07:47:08ZUnexpected solution to ODE with dependent parameter<p>Hello,</p><p>For my research, I am required to numerically solve the following first-order ODE in 'μ' that describes the electron mobility through a channel as a function of gate voltage in a field effect transistor (Vg ranges from 40V to -50V):</p><img src = "/matlabcentral/answers/uploaded_files/105253/eq.PNG"><p>We can wrap up the constants into 'c' nicely and put this in standard form:</p><img src = "/matlabcentral/answers/uploaded_files/105257/eq2.PNG"><p>Now the value dId/dg is determined from experimental data at each Vg. and is represented in my data as a column vector. This is the 'dependent parameter'. In my code, I wrap it into the constant 'c'.</p><pre> VG=DOWN(:,1); %Raw data column vectors of length 901
ISD=DOWN(:,4);</pre><pre> L=20.5E-6; %constants
W=100E-9;
eox=3.9;
e0=8.85E-12;
tox=300E-9;
VD=0.1;
VT=-50</pre><pre> dISDdVG=diff(ISD)./diff(VG); %estimate derivative</pre><pre> u0=0.0051; %initial condition</pre><pre> const=zeros(length(dISDdVG),1); %preallocate constant array</pre><pre> VGG=VG(1:900,1); %differentiation of length n array makes length n-1 array, so we need to adjust. </pre><pre> for i=1:length(dISDdVG) %combine constants and derivative
const(i)=(L*tox*dISDdVG(i))./(W*eox*e0*VD);
end</pre><pre> [gate,mobility]=ode45(@(vg,u) odefcn(vg,u,VGG,const,VT),VG.',u0); %solve ODE</pre><pre> plot(gate,mobility,'ro') %plot solution</pre><pre> function dUdVG=odefcn(vg,u,VGG,const,VT) %declaration of ODE
constUse=interp1(VGG,const,vg);
dUdVG=(constUse-u)./(vg-VT);
end</pre><p>The answer that I am getting does not really match my expectation, so I wonder if there is something wrong with my approach. Thank you for any help.</p><p>I came to this way of solving it based on the help section for ODE45 which explains how to solve an ODE with 'time-dependent' parameters. Also, a helpful discussion from this stackexchange question:</p><p><a href = "https://stackoverflow.com/questions/14343563/how-solve-a-system-of-ordinary-differntial-equation-with-time-dependent-paramete">https://stackoverflow.com/questions/14343563/how-solve-a-system-of-ordinary-differntial-equation-with-time-dependent-paramete</a></p>Michael Randlehttps://cn.mathworks.com/matlabcentral/profile/authors/9864637-michael-randletag:cn.mathworks.com,2005:Question/3775032018-01-16T22:22:17Z2018-02-19T07:45:30ZHow do I pull the specific data I need from a text file?<p>I have an output file from which I am trying to pull specific data and plot it. I added comments in the format "% FIRST LINE OF X VALUES" to the file for the sake of people looking at my question being able to see which values I am trying to pull, however these comments are not in the actual output file. I am trying to pull two specific blocks of values from this file, one of "x" values and one of "y" values, and plot them and while I know how to plot the data once I've extracted it, I am not sure how to pull the data correctly from the file. For those trying to help, the data I need to pull is near the end of the attached file. Any ideas are greatly appreciated!</p>Jessica Maxsonhttps://cn.mathworks.com/matlabcentral/profile/authors/5546755-jessica-maxsontag:cn.mathworks.com,2005:Question/3834452018-02-19T06:41:10Z2018-02-19T07:43:45Zwhile loop error with conditional statment<pre class="language-matlab">i %ignore this i code starts from below
interval = 1.2
x_int = 0:intereval:c
i=1
while x_int(i) <= c
ya(i) = ((5*c)*(TT/100))*((0.2969*sqrt(x_int(i)/c))-(0.126*(x_int(i)/c))-...
(0.3516*(x_int(i)/c)^2)+(0.2843*(x_int(i)/c)^3)-(0.1015*(x_int(i)/c)^4));
yb(i)= -((5*c)*(TT/100))*((0.2969*sqrt(x_int(i)/c))-(0.126*(x_int(i)/c))-...
(0.3516*(x_int(i)/c)^2)+(0.2843*(x_int(i)/c)^3)-(0.1015*(x_int(i)/c)^4));
i=i+1
end
</pre><p>Here c can be any whole number (assuming it's bigger than its interval). when i run this i get an error saying Index exceeds matrix dimensions. at while x_int(i) <= c Please help!</p>PetronasAMGhttps://cn.mathworks.com/matlabcentral/profile/authors/7907889-petronasamgtag:cn.mathworks.com,2005:Question/3834112018-02-19T00:55:48Z2018-02-19T07:42:40ZDifferentiation, Minima and Maxima<p>I want to differentiate the following loop for an induction motor with respect to (s) and find the minima and maxima:</p><pre class="language-matlab">for ii = 1:51
t_ind1(ii) = (3 * v_th^2 * r2 / s(ii)) / ...
(w_sync * ((r_th + r2/s(ii))^2 + (x_th + x2)^2) );
end
</pre><p>Which is the best method/approach to achieve this?</p><p>Frank</p>Frank Lehmannhttps://cn.mathworks.com/matlabcentral/profile/authors/8478007-frank-lehmanntag:cn.mathworks.com,2005:Question/3833892018-02-18T20:16:21Z2018-02-19T07:41:30ZHello everyone! I need your valuable help here.<p>I have a 3D matrix (12 x 14 x 360) which is 30 years monthly data.
I need only months from Apri to September from all 30 years. The output matrix I expect is 12 x 14 x 180. I am getting this error: “Subscripted assignment dimension mismatch.” Correct me please.</p><pre> % code
h=1:180
for year=1:30;
April=(year-1)*12+4;
Sept=(year-1)*12+9;
seasons(:,:,h)=mat(:,:,April:Sept);
end</pre><p>Kindly, Emgdaw</p>Engdaw Chanehttps://cn.mathworks.com/matlabcentral/profile/authors/9673402-engdaw-chanetag:cn.mathworks.com,2005:Question/3834402018-02-19T06:25:00Z2018-02-19T07:37:19Zi want to keep just the object which there is circle inside it and remove other objects from image <p>I need help on the following code it's working but I don't know how to remove the object which don't have a black circle inside it can any one help (this code for keep the roundness object which threshold>0.65 and remove others so the roundness object have a circle inside as image attachment)please any one help update on the same code thanks
bw = imread('segment.jpg');
imshow(bw);</p><p>bw = rgb2gray(bw);
%bw = imbinarize(bw);
%imshow(bw)</p><pre> % remove all object containing fewer than 30 pixels
bw = bwareaopen(bw,30);</pre><pre> % fill a gap in the pen's cap
se = strel('disk',4);
bw = imclose(bw,se);</pre><p>% fill any holes, so that regionprops can be used to estimate
% the area enclosed by each of the boundaries
bw = imfill(bw,'holes');</p><p>%imshow(bw)</p><p>[B,L] = bwboundaries(bw,'noholes');</p><p>% Display the label matrix and draw each boundary
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 1)
end</p><p>stats = regionprops(L,'Area','Centroid');</p><p>threshold = 0.65;</p><p>% loop over the boundaries
for k = 1:length(B)</p><pre class="language-matlab">% obtain (X,Y) boundary coordinates corresponding to label 'k'
boundary = B{k};
</pre><pre class="language-matlab">% compute a simple estimate of the object's perimeter
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));
</pre><pre class="language-matlab">% obtain the area calculation corresponding to label 'k'
area = stats(k).Area;
</pre><pre class="language-matlab">% compute the roundness metric
metric = 4*pi*area/perimeter^2;
</pre><pre class="language-matlab">% display the results
metric_string = sprintf('%2.2f',metric);
</pre><pre class="language-matlab">% mark objects above the threshold with a black circle
</pre><pre class="language-matlab">if metric > threshold
centroid = stats(k).Centroid;
plot(centroid(1),centroid(2),'ko');
</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',...
'FontSize',14,'FontWeight','bold');
</pre><p>end</p><p>title(['Metrics closer to 1 indicate that ',...
'the object is approximately round']);</p>alaa shamasnehhttps://cn.mathworks.com/matlabcentral/profile/authors/8364697-alaa-shamasnehtag:cn.mathworks.com,2005:Question/2241852015-06-17T07:53:44Z2018-02-19T07:36:24ZHow to make long title for a plot with automatic line breaks?<p>I would like to use a very long title, which should have lots of line breaks, but I want to put line breaks automatically to achieve a kind of justified paragraph visually.</p>Mr M.https://cn.mathworks.com/matlabcentral/profile/authors/4980938-mr-mtag:cn.mathworks.com,2005:Question/3834052018-02-19T00:08:29Z2018-02-19T07:33:21Zextract rescale slope value <p>Hi all,</p><p>I want to extract the RescaleSlope value from dicominfo for each slice. But I have 135 slice images. This is my code to extract RescaleSlope. But still failed.</p><pre class="language-matlab">P = zeros(256, 256, 135);
for K = 1 : 135
petname = sprintf('PET_I1001_PT%03d.dcm', K);
P(:,:,K) = dicominfo(petname);
end
info=dicominfo(P(:,:,K));
[r,c,slice] = findND (info.RescaleSlope);
</pre><p>Anyone who can help me solve this problem???</p>mohd akmal masudhttps://cn.mathworks.com/matlabcentral/profile/authors/10957567-mohd-akmal-masudtag:cn.mathworks.com,2005:Question/3834492018-02-19T07:27:23Z2018-02-19T07:27:23ZHow to make genetic algorithm output only one powerloss result<p>Hello everyone
i am new here. I am having a problem with my genetic algorithm. i am doing a project on optimal placement of distributed generation to minimise using both PSO and GA to compare. My genetic algorithm is giving several values of powerloss for one time i am running. i do not know how to get only one answer for the GA just like in PSO. can anyone help me please? i can send my code so that you can see.
thank you</p>Aisha Jahangeerhttps://cn.mathworks.com/matlabcentral/profile/authors/12190099-aisha-jahangeertag:cn.mathworks.com,2005:Question/3834292018-02-19T04:57:52Z2018-02-19T07:26:03ZBytesAvailableFcn and hObject Scope<p>Hi,</p><p>I am using GUIDE, I have a button that opens a serial connection and configures the bytes available function as such:</p><pre> handles.s.BytesAvailableFcn = {@update_function,hObject};</pre><p>The callback function is as such:</p><pre class="language-matlab">function update_function(hObject,eventdata,hfigure)
handles = guidata(hfigure);
B=zeros(7,7);
B(:)= single(42.0);
%Set the temp axes
axes(handles.temp_axes);
handles.current_data = B;
image(handles.current_data,'CDataMapping','scaled');
</pre><p>Instead of plotting the data on the existing temp axes, it creates a new figure window and plots it there, so I know somehow I have the scope wrong. Can someone see where I've gone wrong?</p><p>Cheers</p>Martin Thompsonhttps://cn.mathworks.com/matlabcentral/profile/authors/11625976-martin-thompsontag:cn.mathworks.com,2005:Question/3831952018-02-17T05:20:06Z2018-02-19T07:19:32ZCan anyone one tell me on which power grid (https://in.mathworks.com/help/physmod/sps/examples/sssc-phasor-model.html?s_tid=srchtitle) this simulation has been done..<p><a href = "https://in.mathworks.com/help/physmod/sps/examples/sssc-phasor-model.html?s_tid=srchtitle">https://in.mathworks.com/help/physmod/sps/examples/sssc-phasor-model.html?s_tid=srchtitle</a></p>achu ramhttps://cn.mathworks.com/matlabcentral/profile/authors/12015926-achu-ramtag:cn.mathworks.com,2005:Question/3834432018-02-19T06:33:10Z2018-02-19T07:16:42ZFunction to find the next prime number...<p>I have a vector of size 1*152.Now i want to find the next prime number of every number present in the vector..</p><p>Ex: My vector is a=[2 4 7 8] i want the output as [2 5 7 11]..i.e., if the number is a prime then that number will be the output i.e., like 2 and 7 in the given example...</p><p><b>I tried using nextprime like below it gives the following error:</b></p><p><b>case 1:</b></p><pre class="language-matlab">>>nextprime(sym(100))
Undefined function 'nextprime' for input arguments of type 'sym'.
</pre><p><b>case 2:</b></p><pre class="language-matlab">>> nextprime(3)
Undefined function 'nextprime' for input arguments of type 'double'.
</pre>Jyothi Alugoluhttps://cn.mathworks.com/matlabcentral/profile/authors/9669677-jyothi-alugolutag:cn.mathworks.com,2005:Question/3834462018-02-19T06:51:17Z2018-02-19T07:15:01ZHow to insert two diagonals in odd matrix<p>What's the most efficient way to insert a diagonal of 1's and -1's in an odd zero matrix? I've tried messing around with lower and upper triangular matrices, inserting one matrix into another but still cant figure out how to get it.</p><p>For example in the picture below you have a (n-1)x(n) zero matrix and want to insert that diagonal of 1's and -1's about the main diagonal.</p><p>Any help would be appreciated!</p><p>Thanks</p>Ramin Mousacohenhttps://cn.mathworks.com/matlabcentral/profile/authors/8893945-ramin-mousacohentag:cn.mathworks.com,2005:Question/3834412018-02-19T06:26:42Z2018-02-19T07:13:44ZLoad flow study with power electronic interfaces<p>I'm simulating a network consisting of synchronous machines and loads. I need to modify the network by adding type iv (full converter based) wind generators. After connecting a type iv wind generator and running load flow study I cannot get a power reference (the result is NaN) for the wind generator. Is is possible to run a load flow study in simulink when synchronous machine are connected through power electronic interfaces?</p>Dayan Rathnayakehttps://cn.mathworks.com/matlabcentral/profile/authors/10746533-dayan-rathnayaketag:cn.mathworks.com,2005:Question/3833122018-02-18T05:34:51Z2018-02-19T07:08:00ZI need help on following<p>I want Adaptive Wiener filter and compare it with median and average filter and show how adaptive wiener filter is better than other two.</p>Komal Gaikwadhttps://cn.mathworks.com/matlabcentral/profile/authors/8607151-komal-gaikwadtag:cn.mathworks.com,2005:Question/3834202018-02-19T03:17:46Z2018-02-19T06:51:55ZSubscript indices must either be real positive integers or logicals.<p>Hey guys,</p><p>getting this error for what should be a simple task. Any idea on what I´m missing?</p><p>Simply trying to convert an excel file in a way that I get prices on business days only. Mapping seems to work & when I do it only to monthly accuracy it works too.</p><p>Thanks!</p><pre class="language-matlab">if true
% Retrieve all days
dates = (data(1):data(end,1))';
% Remove weekends and holidays
dates = dates(isbusday(dates));
% Map longer ts to short
[tf,loc] = ismember([day(dates) month(dates) year(dates)],...
[day(data(:,1)) month(data(:,1)) year(data(:,1))],'rows')
</pre><pre class="language-matlab">% create fints
out = fints(dates,data(loc,2))
</pre><pre class="language-matlab">end
</pre>Albanhttps://cn.mathworks.com/matlabcentral/profile/authors/12130763-albantag:cn.mathworks.com,2005:Question/3834332018-02-19T05:24:09Z2018-02-19T06:45:42ZHow can I solve this ODE equation?<p>I have variable "Y" which is dependent on single variable "x". I want to solve following equation:</p><p>d(Y(x))/dx==0</p><p>It looks simple. I don't have any initial or boundary conditions.</p>Luqman Saleemhttps://cn.mathworks.com/matlabcentral/profile/authors/9731121-luqman-saleemtag:cn.mathworks.com,2005:Question/1207372014-03-09T06:08:27Z2018-02-19T06:40:51ZHow to set default aspect ratio of 2D-3D plot in Matlab<p>Hi ,</p><pre> How can I set pbaspect([2.5 3.5 1]) in the startup.m file for every plot?
Thanks,</pre>John Aunghttps://cn.mathworks.com/matlabcentral/profile/authors/3169386-john-aungtag:cn.mathworks.com,2005:Question/3834392018-02-19T06:09:08Z2018-02-19T06:36:15ZCan someone please help you figure out why this is not plotting <pre class="language-matlab">AR=2.5;
sale=(45/180)*pi;
t=0;
for M=0.2:0.75;
t=t+1;
k=1+(((AR)*(1.87-0.000233*sale))/100);
clalpha=(((2*pi)*AR)/(2+(sqrt(((((AR^2)*(1-M^2)/k^2)*(1+(((tan(sale))^2)/(1-M^2))))))))+4);
end
figure
plot(0.2:0.75,clalpha)
</pre>Jonas Amoama Breduhttps://cn.mathworks.com/matlabcentral/profile/authors/6790158-jonas-amoama-bredutag:cn.mathworks.com,2005:Question/595822013-01-22T21:53:43Z2018-02-19T06:34:50ZODE45 errer :input argument y is undefined <p>hi everybody, i've got a problem and it drives me crazy...</p><p>In a function i defined a systeme :</p><pre class="language-matlab">function dy=f_iso(t,y)
</pre><pre class="language-matlab">global Q b K n E sigma0 epoint
</pre><pre class="language-matlab">if abs(y(1))-(Q*(1-exp(-b*y(3))))-sigma0<0
</pre><pre> dy(3)=0;</pre><pre class="language-matlab">else
</pre><pre> dy(3)=((abs(y(1))-(Q*(1-exp(-b*y(3))))-sigma0)/K)^n;</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">dy(2)=sign(y(1))*dy(3);
</pre><pre class="language-matlab">dy(1)=E*(epoint-dy(2));
</pre><pre class="language-matlab">dy=dy';
</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">Then i've used ode45 such as : global Q b n E sigma0 epoint
</pre><pre class="language-matlab">Q=-150;
</pre><pre class="language-matlab">b=5;
</pre><pre class="language-matlab">n=6;
</pre><pre class="language-matlab">sigma0=200;
</pre><pre class="language-matlab">E=140000;
</pre><pre class="language-matlab">epoint=0.001;
</pre><pre class="language-matlab">[t,y]=ode45('f_iso',[0 10],[0 0 0]);
</pre><pre class="language-matlab">sigma1=y(1,:);
</pre><pre class="language-matlab">ep1=y(3,:);
</pre><pre class="language-matlab">e1=sigma1/E+ep1;
</pre><pre class="language-matlab">plot(e1,sigma1)
</pre><p>but there is qn error :</p><pre class="language-matlab">Input argument "y" is undefined.
</pre><pre class="language-matlab">Error in ==> f_iso at 8
</pre><p>and i don't know whyt...</p><p>thanks</p>tonyhttps://cn.mathworks.com/matlabcentral/profile/authors/3853570-tonytag:cn.mathworks.com,2005:Question/3830952018-02-16T14:26:29Z2018-02-19T06:34:25ZError using parallel.gpu.CUDADevice.hBuild An unexpected error occurred trying to retrieve CUDA device properties. The CUDA error was: CUDA_ERROR_UNKNOWN<p>Hello I am getting error while running nueral network programs the error is "Error using parallel.gpu.CUDADevice.hBuild
An unexpected error occurred trying to retrieve CUDA device properties. The CUDA error was:
CUDA_ERROR_UNKNOWN" few days back it used to run properly from 2 days it is displaying this error. even i tried updating drivers no use. please help me .</p>Pramod Raohttps://cn.mathworks.com/matlabcentral/profile/authors/11444263-pramod-raotag:cn.mathworks.com,2005:Question/3834422018-02-19T06:27:21Z2018-02-19T06:30:26ZUsing dec2hex within a pattern<p>Hi:</p><p>In the attached file, I am counting the occurrence of matched strings in columns 2, 3, and 6. The element in TN_Hex is searched in column 2, the elements in DS_Hex are searched in column 3, and the string 'Hi is searched in column 6.</p><p>In my case, I want to enter the elements of set TN_Hex in its decimal form as shown in TN_Dec, and the elements in DS_Hex to its decimal form as in DS_Dec. Note the pattern "fe80::c30c:0:0:...", which is what I have in the xls file. I am thinking to use dec2hex for the elements in TN_Dec, and DS_Dec and put it in the space of the pattern "fe80::c30c:0:0:..." and perform the occurrence counting. In other words I want to avoid entering elements in the lengthy way, the Hex form, since the set might contain too many elements.</p><p>The code below finds the occurrence of patterns in columns 2, 3, and 6</p><pre class="language-matlab">clc; clear;
</pre><pre class="language-matlab">TN_Dec={'1'};%The preferred way
</pre><pre class="language-matlab">TN_Hex = {'fe80::c30c:0:0:1'};
</pre><pre class="language-matlab">DS_Dec={'15','16','17','18','19','20'};%The preferred way
</pre><pre class="language-matlab">DS_Hex = {'fe80::c30c:0:0:F','fe80::c30c:0:0:10','fe80::c30c:0:0:11','fe80::c30c:0:0:12','fe80::c30c:0:0:13','fe80::c30c:0:0:14'};
</pre><pre class="language-matlab">[num,txt,raw] = xlsread('Example.xls');
</pre><pre class="language-matlab">Col2= cellfun(@num2str,raw(:,2),'uni',0);
</pre><pre class="language-matlab">Col3= cellfun(@num2str,raw(:,3),'uni',0);
</pre><pre class="language-matlab">Col6= cellfun(@num2str,raw(:,6),'uni',0);
</pre><pre class="language-matlab">idx = strcmp(Col2,TN_Hex) & ismember(Col3,DS_Hex) & strcmp(Col6,'Hi');
</pre><pre class="language-matlab">Numofoccurrence=nnz(idx);
</pre><p>I appreciate your suggestions.</p>Haidi Bobhttps://cn.mathworks.com/matlabcentral/profile/authors/12107408-haidi-bobtag:cn.mathworks.com,2005:Question/3834272018-02-19T04:43:27Z2018-02-19T06:25:25ZProper importing of MATLAB structures into Python<p>I have a MATLAB (2017b) structure which is saved (attached) as lib.mat. This structure, at its highest level, is basically a library with three different fields including an array of structures: ['name', 'structures' [1 x 32 struct], 'structlist', {1 x 32 cell}].</p><p>I have tried two different methods to import this structure into Python (v3.5):</p><p>a) Import using the io module from Scipy library</p><pre class="language-matlab">import scipy.io as spio
lib = spio.loadmat('lib.mat')
</pre><p>which produces a dict in python called 'lib' whose fields are not accessible (at least I am not aware how to access, for example, the 32 structures listed in the field 'structures' [1 x 32 struct]).</p><p>b) calling MATLAB engine in Python (v3.5) and using getfield function to access different fields of the structure:</p><pre class="language-matlab">import matlab.engine
eng = matlab.engine.start_matlab()
Obj = eng.load('lib.mat')['lib']
Names = eng.getfield(Obj, 'name')
Strs = eng.getfield(Obj, 'structures')
StrLists = eng.getfield(Obj, 'structlist')
</pre><p>where everything works but</p><pre class="language-matlab">Strs = eng.getfield(Obj, 'structures')
</pre><p>is not able to restore the 32 structures in variable Strs.
For example if you try:</p><pre class="language-matlab">>>> eng.size(StrLists)
</pre><p>the result would be: matlab.double([[1.0,32.0]]), which is correct, but if you try</p><pre> >>> eng.size(Strs)</pre><p>the results is: matlab.double([[0.0,0.0]]), which is incorrect (must be the same size as StrList).</p><p>Now my question is how to properly import such data structures into Python and access to their fields.</p><p>Thanks</p>Milad Khttps://cn.mathworks.com/matlabcentral/profile/authors/10723178-milad-ktag:cn.mathworks.com,2005:Question/1151502014-02-06T20:24:45Z2018-02-19T06:14:57ZHow to make script and command window adjacent<p>I'm new to MATLAB and am still getting used to the workspace. When I open a new file or script, it always comes out in a new window. How can I get it to be opened in the same window as the commands? Thanks!</p>Amyhttps://cn.mathworks.com/matlabcentral/profile/authors/3658914-amytag:cn.mathworks.com,2005:Question/3833232018-02-18T08:52:29Z2018-02-19T06:13:36ZConcatenating array using for loop<p>I have a structure with some arrays listed like this from 1 to 9 :</p><p>Cure.neat(1).temps</p><p>Cure.neat(2).temps</p><p>.....</p><p>I would like to combine the arrays into one matrix such as:</p><p>A = [ Cure.neat(1).temps Cure.neat(2).temps etc... ]</p><p>for i = 1 :9</p>aldburghttps://cn.mathworks.com/matlabcentral/profile/authors/11535393-aldburgtag:cn.mathworks.com,2005:Question/3834372018-02-19T06:02:18Z2018-02-19T06:12:34ZFast Fourier Transform (FFT) function won't work for more than 1x1 array of circular apertures<p>Below is a program that generates an NxN array of circular apertures and uses fast fourier transform (FFT) function to produce a diffraction pattern.</p><pre> n_circles=4 % Define the number of circles to be plotted
n0 = (2^10)/n_circles; % Define the size of the basic mask
M0 = zeros(n0); % Initialize the basic mask
I = 1:n0; % Define the x and y coordinates of the basic mask
x = I - n0/2;
y = n0/2 - I;
[X,Y] = meshgrid(x,y); % Create the mask
R = n0/2; % Define the radius of the basic circle
A = (X.^2 + Y.^2 <= R^2); % Get the indices of the points inside the basic circle
M0(A) = 1; % Set basic mask
figure
M=repmat(M0,n_circles,n_circles); % Replicate basic mask according to the number of circles to be plotted
imagesc(M)
daspect([1 1 1])
%Fast fourier transform (FFT)
DP = fftshift(fft2(M));
imagesc(abs(DP))
axis image
imagesc(abs(log2(DP)))
axis image</pre><p>When the number of circles (n_circles) is 1, the output looks right, as shown in figure 1. But when the n_circles is raised to a number higher than 1, the program produces bad results. As an example, figure 2 shows the result for a 2 by 2 array of circles.</p><img src = "/matlabcentral/answers/uploaded_files/105291/1by1_array_of_circles.bmp"><p>figure 1. result for 1 circular aperture.</p><img src = "/matlabcentral/answers/uploaded_files/105292/2by2_array_of_circles.bmp"><p>figure 2. result for 2 by 2 array of circular apertures.</p><p>Can anyone help me fix the problem? Thanks.</p>Viron Gil Estradahttps://cn.mathworks.com/matlabcentral/profile/authors/11916742-viron-gil-estradatag:cn.mathworks.com,2005:Question/3832072018-02-17T08:20:56Z2018-02-19T06:12:19ZHow to find which postions in a vector has negative values and output them?<p>i have a vector and need to find the postions which has negative values</p>sairohith mudduluruhttps://cn.mathworks.com/matlabcentral/profile/authors/8738481-sairohith-muddulurutag:cn.mathworks.com,2005:Question/3834092018-02-19T00:38:27Z2018-02-19T05:59:28ZFOR loop skipping to a particular iteration<pre class="language-matlab">for i=2:1:(length(time_c)-1)
</pre><pre class="language-matlab">if wheelpower_c(i)>= 0
</pre><pre> propulsionpower(i)=propulsionpower(i-1)+wheelpower_c(i);</pre><pre class="language-matlab">Regenpower(i)=Regenpower(i-1);
</pre><pre class="language-matlab">Brakeloss(i)=Brakeloss(i-1);
</pre><pre class="language-matlab">I(i)=(Voc-sqrt((Voc^2)-(4*R.*batterypower_city(i))))/(2*R);
</pre><pre class="language-matlab">Soc(i)=Soc(i-1)-(I(i)*DT/battery_capacity_C);
</pre><pre class="language-matlab">V(i)=Voc-R*I(i);
</pre><p>this a part of my for loop and i wanna check whether my conditions hold at i=576 can i skip to that particular iteration? Thank you</p><p>length(time_c)=1374</p>sairohith mudduluruhttps://cn.mathworks.com/matlabcentral/profile/authors/8738481-sairohith-muddulurutag:cn.mathworks.com,2005:Question/3834362018-02-19T05:58:24Z2018-02-19T05:58:24ZHow to automatically generate/create input/output data from the rule viewer in 'Fuzzy Logic Designer' ?<p>I have created a <b>'Sugeno'</b> type Fuzzy logic system in <b>'Fuzzy Logic Designer'</b>, now i need to get data from this system for training in <b>'Neuro Fuzzy Designer'</b>
To create or generate data of like 500 input/output points, it will take too much time, secondly, if i make some alterations in membership functions or rules, i have to retake the data values, so, that will be very time consuming.
What i need is that, a code or some procedure to <b>automatically get data from the rule viewer</b>.</p>Muhamad Arslan Shahidhttps://cn.mathworks.com/matlabcentral/profile/authors/8051671-muhamad-arslan-shahidtag:cn.mathworks.com,2005:Question/3834302018-02-19T05:00:42Z2018-02-19T05:57:55Zi have a CAN message, whose signal values has to be varied.How should i vary the signal values.Could anyone explain the procedure in simulink.Thanks in advance. <p>i have a CAN message, whose signal values has to be varied.How should i vary the signal values.Could anyone explain the procedure in simulink.Thanks in advance.</p>Sai Vaddihttps://cn.mathworks.com/matlabcentral/profile/authors/11201288-sai-vadditag:cn.mathworks.com,2005:Question/3834142018-02-19T01:51:31Z2018-02-19T05:56:40ZHow to re-write these multiple codes in a single code?<p>Hi,</p><p>I am getting the interpolation of 400 data from 100 plots. I have built one code and duplicated it into 400 copies in the same page to run the interpolation automatically. I would like to ask if it is possible to make these multiple codes only one, as I realized that the run time is too long. I am giving two sets of the codes below. The interpolation steps are as follows:
The steps are as follows:</p><p>1) Plot z1 = x1,y1 data; Interpolate the first column data from z1</p><p>2) Plot z2 = x2,y2 data; Interpolate the first column data from z2;</p><p>This will continue until the 100 plots finish. Then the same process starts for the second column, and so on until the 400th column.</p><p>In every step, the following part of code is the only part that changes in increments:</p><pre class="language-matlab">b=A(:,2); %ith column is assigned to b variable at every step (in this step, it is 2)
y2 (:, 2) = b; %ith column (in this step, it is 2)
x2 (k,:) = interp1(y3, x3, y2(:,2), 'linear'); %ith column (in this step, it is 2)
temp=x2(k,:);
temp(isnan(temp))=0.05;
x2(k,:)=temp;
fid=fopen(['result_' num2str(2) '.txt'],'w');%ith column (in this step is is 2)
fprintf(fid,'%f\n',x2);
fclose(fid);
end
end
</pre><p>The two sets of codes are as follows:</p><pre class="language-matlab">%% Code 1%%
</pre><pre class="language-matlab">clear; clc;
Folder = cd;
N=100;
x2 = zeros(N, 10);
for k = 1:N;
Driftt = sprintf('Drift%d.out', k);
Reactt = sprintf('React%d.out', k);
matDrift = importdata(fullfile(Folder, Driftt));
matReact = importdata(fullfile(Folder, Reactt));
x1= matDrift(:,2);
y1= -sum(matReact(:,2:11),2);
[x3, ix] = unique(x1);
y3 = y1(ix);
A=dlmread('AllPiers2.txt');
for i=1:size(A,2)%number of columns
b=A(:,1);%ith column is assigned to b variable at every step
y2 (:,1) = b;
x2 (k,:) = interp1(y3, x3, y2(:,1), 'linear');
temp=x2(k,:);
temp(isnan(temp))=0.05;
x2(k,:)=temp;
fid=fopen(['result_' num2str(1) '.txt'],'w');
fprintf(fid,'%f\n',x2);
fclose(fid);
end
end
</pre><pre class="language-matlab">%% Code 2%%
</pre><pre class="language-matlab">clear; clc;
Folder = cd;
N=100;
x2 = zeros(N, 10);
for k = 1:N;
Driftt = sprintf('Drift%d.out', k);
Reactt = sprintf('React%d.out', k);
matDrift = importdata(fullfile(Folder, Driftt));
matReact = importdata(fullfile(Folder, Reactt));
x1= matDrift(:,2);
y1= -sum(matReact(:,2:11),2);
[x3, ix] = unique(x1);
y3 = y1(ix);
A=dlmread('AllPiers2.txt');
for i=1:size(A,2)%number of columns
b=A(:,2);%ith column is assigned to b variable at every step
y2 (:,2) = b;
x2 (k,:) = interp1(y3, x3, y2(:,2), 'linear');
temp=x2(k,:);
temp(isnan(temp))=0.05;
x2(k,:)=temp;
fid=fopen(['result_' num2str(2) '.txt'],'w');
fprintf(fid,'%f\n',x2);
fclose(fid);
end
end
</pre>Ismail Qeshtahttps://cn.mathworks.com/matlabcentral/profile/authors/10292327-ismail-qeshtatag:cn.mathworks.com,2005:Question/3829712018-02-15T22:32:05Z2018-02-19T05:54:21ZHow to combine 4 .txt files in a single.txt file?<p>I have 4 .txt files, they've the same number of lines, but different numbers of columns.</p><p>The number one is like:</p><pre class="language-matlab">A
B
C
D
</pre><p>The number 2 is like:</p><pre class="language-matlab">1 x
2 y
3 z
4 w
</pre><p>I'd like to put then like that:</p><pre class="language-matlab">A 1 x
B 2 y
C 3 z
D 4 w
</pre>Bruno Souzahttps://cn.mathworks.com/matlabcentral/profile/authors/11799514-bruno-souzatag:cn.mathworks.com,2005:Question/3832982018-02-18T02:26:06Z2018-02-19T05:47:12ZHow can I randomly generate data in 2D plane for 2 classes -1 and +1 ?<p>Randomly generating data in 2D plane for 2 classes (-1 and +1). Using the same data to run PLA algorithm to find the best hypothesis or perceptron that best separates the two classes.</p>Roneel Kumarhttps://cn.mathworks.com/matlabcentral/profile/authors/12132729-roneel-kumartag:cn.mathworks.com,2005:Question/3833992018-02-18T22:10:31Z2018-02-19T05:45:24ZI need Script that evaluate the critical points for COMPLEX FUNCTION for any complex function f(z)<p>I need Script that evaluate the critical points for COMPLEX FUNCTION for any complex function f(z)
can any one help me ?</p>Shuaa M. Azizhttps://cn.mathworks.com/matlabcentral/profile/authors/284372-shuaa-m-aziztag:cn.mathworks.com,2005:Question/3834232018-02-19T04:10:18Z2018-02-19T05:37:11Zmoving average of unevenly spaced time data<p>Hello,</p><p>I have the following data, and need to average the signal data as per defined window size. Any help?</p><pre class="language-matlab">signal= [0.1 0.2 0.15 0.3]; % volt reading
</pre><pre class="language-matlab">time_signal = [3.5 5.5 6.5 10.5];% seconds after event, the time when signal was recorded
</pre><pre class="language-matlab">time_regular = [ *1 2 3 4* 5 6 7 8 *9 10 11 12 13*]; time in seconds
</pre><p>Window_size is 4, 4 and 5. I want to average the signal data that falls within first 4 seconds, then next 4 seconds and finally in next 5 seconds. I highlighted the window sizes in time_regular array.</p><p>The answer is 0.1, 0.175 and 0.3. The calculation is done as follows. In first 4 seconds there is only one signal data point that falls within first 4 seconds, therefore first value is 0.1. In next 4 seconds, there are two signal data points (0.2 and 0.15), therefore the average of these two points is 0.175. In next 5 seconds, there is only one signal data point (0.3), therefore the average is 0.3.
I can do this using for loop, but I have 100s of window sizes and big data.</p><p>Any matlab function can do this trick?</p>Researchhttps://cn.mathworks.com/matlabcentral/profile/authors/2489014-researchtag:cn.mathworks.com,2005:Question/3834352018-02-19T05:36:50Z2018-02-19T05:36:50ZCan I get Matlab code for image dtection, zooming and identification in a video from a Drone?<p>Can I get Matlab code for image dtection, zooming and identification in a video from a Drone?</p>clementzeehttps://cn.mathworks.com/matlabcentral/profile/authors/12189636-clementzeetag:cn.mathworks.com,2005:Question/3018532016-09-04T00:46:30Z2018-02-19T05:35:23ZCompute the product of the next n elements in matrix<p>I would like to compute the product of the next n adjacent elements of a matrix. The number n of elements to be multiplied should be given in function's input.
For example for this input I should compute the product of the 3 consecutive elements, starting from 1.</p><pre class="language-matlab">[product, ind] = max_product([1 2 2 1 3 1],3);
</pre><p>This gives (4,4,6,3).</p><p>Is there any practical way to do it?
Now I do this using</p><pre class="language-matlab">for ii=1:(length(v)-2)
p=prod(v(ii:ii+n-1));
</pre><p>where v is the input vector and n is the number of elements to be multiplied.</p><p>Depending whether n is odd or even or length(v) is odd or even, I get sometimes right answer but sometimes the following error</p><pre class="language-matlab">Index exceeds matrix dimensions.
</pre><pre class="language-matlab">Error in max_product (line 6)
p=prod(v(ii:ii+n-1));.
</pre><p>Is there any correct general way to do it?</p>Astrikhttps://cn.mathworks.com/matlabcentral/profile/authors/8503615-astriktag:cn.mathworks.com,2005:Question/3834322018-02-19T05:22:26Z2018-02-19T05:34:28Zi want to modify TPVD matrix from 2x2 to 3x3 but how i can change ??? matrix g <p>i want to modify TPVD matrix from 2x2 to 3x3 but how i can change ??? matrix g</p><p>g=a(1+x:2+x,1+y:2+y);</p><pre> g=double(g);
d0=g(1,2)-g(1,1);
d1=g(2,1)-g(1,1);
d2=g(2,2)-g(1,1);
lk=[0 8 16 32 64 128];
uk=[7 15 31 63 127 255 ];</pre>mikiyas teklemariamhttps://cn.mathworks.com/matlabcentral/profile/authors/10693626-mikiyas-teklemariamtag:cn.mathworks.com,2005:Question/113542011-07-11T18:24:54Z2018-02-19T05:32:59ZIncrement file name by adding numbers in a loop<p>I want to select data piecewise in a loop, and I want to be able to save the files as filename_number, where the number increases for each iteration of the loop. Is there an easy way to accomplish this?</p><p>The idea is:
first selection, saved file name is file_1
second selection, saved file name is file_2
etc</p>Amyhttps://cn.mathworks.com/matlabcentral/profile/authors/2244080-amytag:cn.mathworks.com,2005:Question/3834342018-02-19T05:32:13Z2018-02-19T05:32:13ZSir, How to extract color and shape features for a leaf image?<p>To detect disease in an image we need color and shape features to relate to the database.</p>greeshma reddy chowdavaramhttps://cn.mathworks.com/matlabcentral/profile/authors/11855679-greeshma-reddy-chowdavaramtag:cn.mathworks.com,2005:Question/3834212018-02-19T03:21:05Z2018-02-19T05:18:01ZAdd row and column to a interdependent matrix<p>Hi, how to change the below mentioned 'A' matrix to 'AA' matrix by adding a row and column of 'CR' with the exact values for 'CR' as mention below. For 'CR' all the values in the row from CR to E221 will have 0 and in the column, CR will be zero and E1 to E221 will be 1.
I want that string 'CR' also need to be added to the existing headings of E1 to E221 in the row and column wise.</p><img src = "/matlabcentral/answers/uploaded_files/105281/Matrix1.JPG">Santhosh Chandrasekarhttps://cn.mathworks.com/matlabcentral/profile/authors/10517346-santhosh-chandrasekartag:cn.mathworks.com,2005:Question/557172012-12-04T22:34:08Z2018-02-19T05:12:51ZJPEG Image compression using Huffman encoding and decoding<p>Hi everyone,</p><p>i would need some help,
im trying to encode a JPEG Image using Huffman coding.
i know Matlab has huffmanenco, huffmandict functions.
i tried both methods, doesn't work, because the problem is :</p><p>Matlab read Images as Matrix. While the function huffmanenco & huffmandict only accept inputs in vector. So it gives me the error saying : "Input must be a Vector" or sort like that.</p><p>I also found this : <a href = "http://www.mathworks.com/matlabcentral/answers/2158">http://www.mathworks.com/matlabcentral/answers/2158</a>
which leads me here : <a href = "http://www.mathworks.com/matlabcentral/fileexchange/26384-ppt-for-chapter-9-of-matlabsimulink-for-digital-communication">http://www.mathworks.com/matlabcentral/fileexchange/26384-ppt-for-chapter-9-of-matlabsimulink-for-digital-communication</a></p><p>But it doesn't work as well. or at least i still dont know the input for codewords.</p><p>im still working on it.</p><p>anyone can help ?</p>Alif Kusumahhttps://cn.mathworks.com/matlabcentral/profile/authors/3345929-alif-kusumah