https://fr.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2019-02-19T23:05:55Ztag:fr.mathworks.com,2005:Question/4458772019-02-19T18:22:08Z2019-02-19T23:05:55ZImprecision problem: pinv(H) is not equal to pinv(H'*H)*H'I'm testing the function with single hidden layer feedforward neural networks (SLFNs) with 20 neurons, by extreme machine learning (ELM).
With a SLFN, in the output layer, the output weight(OW) can be described by
after adding regularized parameter (regularized ELM), which
with
.
But when I try to calculate and , I find a huge difference between these two when neurons number is over 5 (under 5, they are equal or almost the same).
For example, when is `10*10` matrix, , ,
H= [0.736251410036783 0.499731137079796 0.450233920602169 0.296610970576716 0.369359425954153 0.505556211442208 0.502934880027889 0.364904559142718 0.253349959726753 0.298697900877265;
0.724064281864009 0.521667364351399 0.435944895257239 0.337878535128756 0.364906002569385 0.496504064726699 0.492798607017131 0.390656915261343 0.289981152837390 0.307212326718916;
0.711534656474153 0.543520341487420 0.421761457948049 0.381771374416867 0.360475582262355 0.487454209236671 0.482668250979627 0.417033287703137 0.329570921359082 0.315860145366824;
0.698672860220896 0.565207057974387 0.407705930918082 0.427683127210120 0.356068794706095 0.478412571446765 0.472552121296395 0.443893207685379 0.371735862991355 0.324637323886021;
0.685491077062637 0.586647027111176 0.393799811411985 0.474875155650945 0.351686254239637 0.469385056318048 0.462458480695760 0.471085139463084 0.415948455902421 0.333539494486324;
0.672003357663056 0.607763454504209 0.380063647372632 0.522520267708374 0.347328559602877 0.460377531907542 0.452395518357816 0.498449772544129 0.461556360076788 0.342561958147251;
0.658225608290477 0.628484290731116 0.366516925684188 0.569759064961507 0.342996293691614 0.451395814182317 0.442371323528726 0.525823695636816 0.507817005881821 0.351699689941632;
0.644175558300583 0.648743139215935 0.353177974096445 0.615761051907079 0.338690023332811 0.442445652121229 0.432393859824045 0.553043275759248 0.553944175102542 0.360947346089454;
0.629872705346690 0.668479997764613 0.340063877672496 0.659781468051379 0.334410299080102 0.433532713184646 0.422470940392161 0.579948548513999 0.599160649563718 0.370299272759337;
0.615338237874436 0.687641820315375 0.327190410302607 0.701205860709835 0.330157655029498 0.424662569229062 0.412610204098877 0.606386924575225 0.642749594844498 0.379749516620049];
T=[-0.806458764562879 -0.251682808380338 -0.834815868451399 -0.750626822371170 0.877733363571576 1 -0.626938984683970 -0.767558933097629 -0.921811074815239 -1]';
There is a huge difference between and , where
OW1= [-19780274164.6438 -3619388884.32672 -76363206688.3469 16455234.9229156 -135982025652.153 -93890161354.8417 283696409214.039 193801203.735488 -18829106.6110445 19064848675.0189]'.
OW2 = [-4803.39093243484 3567.08623820149 668.037919243849 5975.10699147077 1709.31211566970 -1328.53407325092 -1844.57938928594 -22511.9388736373 -2377.63048959478 31688.5125271114]';
I also find that if I round , , and return the same answer. So I guess one of the reason might be the float calculation issue inside the matlab.
But since is large, any small change of may result in large difference in the inverse of . I think the function may not be a good option to test. With large ,the numerical imprecision will affect the accuracy of inverse.
Back to my question, in my test, I use 1000 training samples , with noise between , and test samples are noise free. 20 neurons are selected. The can give reasonable results for training, while the performance for is worse. Then I try to increase the precision of by , there's no improvement.
One more comment, when I limit the , can return the reasonable result, and highest accuracy when .
Does anyone know how to solve this?
Sherry Xhttps://fr.mathworks.com/matlabcentral/profile/authors/7567823-sherry-xtag:fr.mathworks.com,2005:Question/4458452019-02-19T16:23:25Z2019-02-19T22:59:14Zerror: too many output argumentsHi! I'm new to MATLAB, so I'd appreciate it if someone could help me. Here is my code for the position analysis of a slider-crank mechanism. Whenever I try to run the code, the command window says: "Error using UnitVector: Too many output arguments. Error in SliderCrank2 (line 29): [e1,n1] = UnitVector(0);"
% SliderCrank_Position_Analysis.m
% performs a position analysis on the slider-crank linkage and
% plots the piston position as a function of crank angle
% by Karolina Kolodziej, February 20, 2019
clear, clc;
a = 0.10; % crank length (m)
b = 0.26; % connecting rod length (m)
c = 0.0; % vertical slider offset
% Ground pins
x0 = [0;0]; % ground pin at A (origin)
% solving for conn. rod angle (theta 3) and piston pos. (d)
N = 361; % # of times to perform calc.
[xB,xC] = deal(zeros(2,N)); % allocate space for pins B and C
[theta2, theta3, d] = deal(zeros(1,N)); %".." for link angles
% Main loop
for i = 1:N
theta2(i) = (i-1)*(2*pi)/(N-1);
theta3(i) = asin((c-a*sin(theta2(i)))/b);
d(i) = a*cos(theta2(i)) + b*cos(theta3(i));
% calculate unit vectors
[e1,n1] = UnitVector(0);
[e2,n2] = UnitVector(theta2(i));
[e3,n3] = UnitVector(theta3(i));
% solve for position of point B
xB(:,i) = FindPos(x0,a,e2);
xC(:,i) = FindPos(xB(:,i),b,e3);
end
plot(theta2*180/pi,d*100,'o','Color',[153/255 153/255 153/255])
hold on
plot(theta2*180/pi,xC(1,:)*100,'Color',[0 110/255 199/255])
title('Piston Position versus Crank Angle for Slider-Crank')
xlabel('Crank angle (degrees)')
ylabel('Position (cm)')
legend('d','xC')
grid on
Karolina Kolodziejhttps://fr.mathworks.com/matlabcentral/profile/authors/14696176-karolina-kolodziejtag:fr.mathworks.com,2005:Question/4459122019-02-19T22:49:55Z2019-02-19T22:57:38ZIs it possible to assign the constant value of a function handle to a variable?Hello,
My program can sometimes generate this function handle:
g = @() 1.0
Or generally: g = @() c , c: constant
Is it possible to transfer that constant into a variable B, so that B = c?
Thanks.
Edit: Is it possible to check whether a function_handle has no inputs(@())?
Panagiotis Panagopoulos Papageorgiouhttps://fr.mathworks.com/matlabcentral/profile/authors/14804881-panagiotis-panagopoulos-papageorgioutag:fr.mathworks.com,2005:Question/4459102019-02-19T22:23:31Z2019-02-19T22:57:21ZHow to fix this error in interpolation?Hi,
I have a set of data to be interpolated for two files. I could use the code below when the second file (representing Y axis) has 11 columns.
However, when the second file (representing Y axis) has only two columns, it shows the following error:
Error using griddedInterpolant
The grid vectors must contain unique points.
Error in interp1 (line 151)
F = griddedInterpolant(X,V,method);
Error in File11 (line 18)
x2 (k,:) = interp1(y3, x3, A(:,i), 'linear');
clear; clc;
Folder = cd;
N=1;
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= -matReact(:,2);
[x3, ix] = unique(x1);
y3 = y1(ix);
A=dlmread('result_all.txt');
for i=1:size(A,2)
x2 (k,:) = interp1(y3, x3, A(:,i), 'linear');
temp=x2(k,:);
temp(isnan(temp))=0.05;
x2(k,:)=temp;
fid=fopen(['result_' num2str(i) '.txt'],'a');
fprintf(fid,'%f\n',x2(k,:));
fclose(fid);
end
end
Ismail Qeshtahttps://fr.mathworks.com/matlabcentral/profile/authors/10292327-ismail-qeshtatag:fr.mathworks.com,2005:Question/4459132019-02-19T22:53:00Z2019-02-19T22:53:00Zpdepe when source term is zero, the total mass still increase over timeHey guys,
I'm trying to solve a simple 1D partial differential equation, but I run into some problem that I can't figure out how to solve it. I don't have a lot of math background.
So, the equation is:
with no-flux boundary condition.
To use pdexpde, for pdex1pde I have:
c = 1;
f = -strain*u*cos(x)*sin(x);
s = (1-u)*kdiss;
where kdiss is in original function, and strain is in original function.
for initial condition pdex1ic, I started with steady state condition, which is:
u0 = 1;
for boundary condition pdex1bc, I used no-flux boundary condition:
pl = 0;
ql = 1;
pr = 0;
qr = 1;
I started with the steady state condition, so I feel like over time the total mass should stay constant. However, increase gradually overtime. The closer strain and kdiss are, the more dramatic this problem becomes. For a rather extreme case, when I turn off source term, such that:
c = 1;
f = -strain*u*cos(x)*sin(x);
s = 0;
Even in this case, the still increase gradually.
I am wondering if anyone could help me with this problem? Thanks a lot for your time and effort!
Best,willhttps://fr.mathworks.com/matlabcentral/profile/authors/2918656-willtag:fr.mathworks.com,2005:Question/4458462019-02-19T16:23:31Z2019-02-19T22:52:44ZCell contents reference from a non-cell array object from a txt fileHi, can you help me I am trying to run a function however gets stuck when I want it to open & read from my txt files where the 1st column is Iaa, 2nd errAA and so on ...
function [results] = kZ(Iaa,errAA,Ibb,errBB,time)
for k = 1:4
textFileName = ['A' num2str(k) '.txt'];
if exist(textFileName, 'file')
fid = fopen(textFileName, 'rt');
mydata = fread(fid);
fclose(fid);
else
fprintf('File %s does not exist.\n', textFileName);
end
end
Iaa = mydata{k}(:,1);
errAA = mydata{k}(:,2);
Ibb = mydata{k}(:,3);
errBB = mydata{k}(:,4);
time = mydata{k}(:,5);
ABsub = Iab - Iab(1);
BAsub = Iba - Iba(1);
[AAcol,AArow] = size(normAA);
if AArow > AAcol
normAA = normAA';
end
[BBcol,BBrow] = size(normBB);
if BBrow > BBcol
normBB = normBB';
end
[ABcol,ABrow] = size(normAB);
if ABrow > ABcol
normAB = normAB';
end
[BAcol,BArow] = size(normBA);
if BArow > BAcol
normBA = normBA';
endAngelo Figueiredohttps://fr.mathworks.com/matlabcentral/profile/authors/7365651-angelo-figueiredotag:fr.mathworks.com,2005:Question/4459112019-02-19T22:48:48Z2019-02-19T22:48:48ZSNR of a signal I want to calculate SNR of a plot signal which is actually phase of the current given by PMU. my data is in excel file having 36001 rows(samples) i want to calculate SNR but by applying differnt conditions and checking these conditions for only 10 samples . How can I do this so that i get my output after every 10 samples?shazmina jamilhttps://fr.mathworks.com/matlabcentral/profile/authors/14544666-shazmina-jamiltag:fr.mathworks.com,2005:Question/4456172019-02-18T17:12:38Z2019-02-19T22:42:52ZHow to load set of images into workspace for training?I'm working on currency recognition. How can i apply set of images of currency notes into workspace in matlab to use for training? Hiruni Gunawardhanehttps://fr.mathworks.com/matlabcentral/profile/authors/14363488-hiruni-gunawardhanetag:fr.mathworks.com,2005:Question/4458862019-02-19T18:59:30Z2019-02-19T22:41:29Zuse more digits in computing in matlabI wrote an iterative solver code in matlab, in which a value update itself usign some computations. In each computation there is an error, which I would like to minimize by using more decimal integers. Any suggestions about how to use more decimal points in computations?Maryamhttps://fr.mathworks.com/matlabcentral/profile/authors/13165062-maryamtag:fr.mathworks.com,2005:Question/4456472019-02-18T19:41:39Z2019-02-19T22:40:18ZAnimal detection in thermal imagesHello everyone. I'm a newbie to MATLAB and I'm kinda struck with a project which detects the animals from the given thermal image.
The tasks are as follows:
Detect the animals and mark it with bounding boxes along with its temperature
Enhancing the image when the contrast is not so good (background and the animal are not distinguishable )
For the above task, can someone plz suggest the methods applicable for detection. So far, I have tried to pre-process the images by masking technique so that I can improve the contrast of the image.
clc;clear;close;
img = imread('C:\Users\DIVYA MEENA\Desktop\1 (79).jpg');
img_gray = rgb2gray(img);
BW = imbinarize(img_gray);
maskedRgbImage = bsxfun(@times, img, cast(BW, 'like', img));
imshow(maskedRgbImage)
However, the above code dint help much.
Any help will be highly appreciated, Thanks in advance and sorry for the long question.
PS: I have attached my sample images. S DIVYA MEENAhttps://fr.mathworks.com/matlabcentral/profile/authors/12747002-s-divya-meenatag:fr.mathworks.com,2005:Question/4459052019-02-19T21:40:10Z2019-02-19T22:29:40Zplot in predesigned figureHello
I have a script, where I tell my programm to create a figure, called h ,looking like the second picture.
then in a function within the scirpt (1. picture) i want matlab to draw my desired plot into the predesigned figure h. (See function in 4. picture)
but instead, matlab doesnt draw my plot into h, matlab draws it as in the 3. picture.
How do i plot into my predesigned figure h?
Thanks for the help!Josefina Ottitschhttps://fr.mathworks.com/matlabcentral/profile/authors/13775798-josefina-ottitschtag:fr.mathworks.com,2005:Question/4453082019-02-16T15:27:29Z2019-02-19T22:25:44ZSlider Code problem with axesthis an example of a slider to control movement on axes
a = get (handles.slider2,'Value')
x = 0:0.1:50;
y = sin (x*a);
plot (handles.axes1,x,y)
and this me trying to apply the example
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
clc;
load ('100m.mat')
a = get(handles.slider2,'Value');
x = 0:0.1:50;
ECGsignal = (val - 1024 )/200;
y = ECGsignal*x*a;
plot (handles.axes1,x,y)
what is the problem in my code ?Hassan Boshahttps://fr.mathworks.com/matlabcentral/profile/authors/14798685-hassan-boshatag:fr.mathworks.com,2005:Question/1689002015-01-04T16:48:54Z2019-02-19T22:24:15ZAnyone knows the syntax to insert a dot above a greek letter in matlab?Wondering how would you insert a dot above a greek letter like gamma dot?
Thanksaamirhttps://fr.mathworks.com/matlabcentral/profile/authors/4819076-aamirtag:fr.mathworks.com,2005:Question/4459082019-02-19T22:05:45Z2019-02-19T22:22:51ZHow to sum multiple matrice in loop ?Hi everybody,
I would like to sum multiple matrice using a loop.
I attach my data.
So, I have a multiple 4D double structure, that contains 4x4x32x12 matrices.
I would like to sum all the matrices according the last argument to obtain 12 matrices which are the sum of the 32 matrices (in my code i = 1:12 ; j = 1:32).
I think I have to use a loop.
Is anybody could help me?
Thanks,
-- ALAnne-Laure GUINEThttps://fr.mathworks.com/matlabcentral/profile/authors/7417618-anne-laure-guinettag:fr.mathworks.com,2005:Question/4459092019-02-19T05:00:00Z2019-02-19T22:14:07ZWhy am I unable to set persistent settings for audioTestBench UI?I'm using the audioTestBench app to tune an audio plugin. Before launching the app, I create a custom instance of a plugin class and then launch audioTestBench with the custom instance as an argument. When the app launches, I modify certain properties on the audioTestBench GUI and then close it. When I relaunch the app, I notice that the settings have been replaced to the default and my changes have vanished. What can I do to make the changes persist?
MathWorks Support Teamhttps://fr.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:fr.mathworks.com,2005:Question/4459072019-02-19T22:04:55Z2019-02-19T22:04:55ZCompiling Multiwindow App built in AppDesignerDoes anyone know if there is a limitation to compiling MultiWindow Apps built in AppDesigner? I followed the tutorial at Creating a Multiwindow App in AppDesigner and the main program and dialog programs work fine on my computer. However, after compiling the main .mlapp file, with the dialog .mlapp file included in the list of needed files, I cannot summon the dialog app through the main app. All the other functionality of the main app seems to be fine, but the callback function to open the dialog window and the functionality therein, are not available. Is there a specific procedure for compiling multi-window apps? Or has anyone had similar issues? Roger Conley Smithhttps://fr.mathworks.com/matlabcentral/profile/authors/13942188-roger-conley-smithtag:fr.mathworks.com,2005:Question/4458992019-02-19T20:34:50Z2019-02-19T22:03:13ZHow do I initialize check box values by clicking another button 'done' in a gui. Below is my code so far:function [r1,r2,r3,r4,r5] = selectProcesses
bg = uibuttongroup('Visible','off',...
'Position',[0 0 1 1],...
'SelectionChangedFcn',@bselection);
% Create three radio buttons in the button group.
r1 = uicontrol(bg,'Style',...
'checkbox',...
'String','Write general outputs .csv of Drive Cycle',...
'Position',[10 350 500 30],...
'HandleVisibility','off');
r2 = uicontrol(bg,'Style','checkbox',...
'String','Write .csv of Avg Batt Power vs Avg Fuel Economy',...
'Position',[10 250 500 30],...
'HandleVisibility','off');
r3 = uicontrol(bg,'Style','checkbox',...
'String','Run 0-60 mph Test and write .csv',...
'Position',[10 150 500 30],...
'HandleVisibility','off');
r4 = uicontrol(bg,'Style','checkbox',...
'String','Run 50-70 mph Test and write .csv',...
'Position',[300 350 500 30],...
'HandleVisibility','off');
r5 = uicontrol(bg,'Style','checkbox',...
'String','Run 7% Grade Test and write .csv',...
'Position',[300 250 500 30],...
'HandleVisibility','off');
% Make the uibuttongroup visible after creating child objects.
bg.Visible = 'on';
function bselection(source,event)
display(['Previous: ' event.OldValue.String]);
display(['Current: ' event.NewValue.String]);
display('------------------');
end
end
Brandon McDonaldhttps://fr.mathworks.com/matlabcentral/profile/authors/13540479-brandon-mcdonaldtag:fr.mathworks.com,2005:Question/4458962019-02-19T20:06:26Z2019-02-19T21:59:42ZReplacing pixel value in a loopHi everyone, Im trying to replace all pixels in rbg image, where the sum of r,g,b components is lower or equal 10 with zero value ([r,b,g]=[0,0,0]) .
If not I want to keep the value from MyImage.
Here is my attempt ...unfortunately not working
MyImage=imread('003264663547_60.jpeg');
RGBsum=(sum(MyImage,3));
NewImage = zeros(size(MyImage));
[a b c]= size(NewImage);
[row column depth]=size(MyImage);
for l=1:depth
for i=1:row
for j=1:column,
if RGBsum <= 10;
NewImage(a,b,c)=0;
else
NewImage(a,b,c)=MyImage(row,column,depth);
end
end
end
end
imshow(NewImage);minehahahttps://fr.mathworks.com/matlabcentral/profile/authors/11605451-minehahatag:fr.mathworks.com,2005:Question/4458742019-02-19T18:10:46Z2019-02-19T21:58:36ZHow can I use simulink without time simulation?Hi everyone,
This is my very first time posting here. Let's say that I'm a "rookie" eager to learn more and more from Matlab and Simulink. I will be starting soon to start some simulink tasks at my job (with help from some guy who knows about Matlab) but I'm developing (or trying) to do some things on my own just to progress.
I want to build a simulink model which has to read the data from an Excel file. The data in the Excel comes from a data acquisition system which has logged:
1 column for air pressure
1 column with time (1 read every 1 milisecond -1kHz-)
The purpose of my model is to read the air pressure value and integrate it but it has to do it according to the corresponding recording time in the cell of the adjacent column. I'm stuck at understanding how simulink performs the simulations because I want the model to introduce the air pressure value read every 1 milisecond as recorded in the data acquisition system but I'm forced to set a simulation time in simulink which doesn't match my data.
How can I tell Simulink "hey, this is my air pressure at 1 milisecond, integrate it, then, this is my air pressure at 2 miliseconds and integrate it" and so on?
I hope my question is clearDavid Rojas Blancohttps://fr.mathworks.com/matlabcentral/profile/authors/13835317-david-rojas-blancotag:fr.mathworks.com,2005:Question/4459062019-02-19T21:56:40Z2019-02-19T21:58:03ZPCA in Matlab reduce dimensionality I just want to have a simple PCA to reduce my dimensionality of let say 400 * 5000 to 400 * 4
meaning reduce from 5000 to 4.
I am not sure where can i set the value of reduction.
coeff = pca(X)
I am trying to follow:
load hald
Then:
The dataset of ingredient is 13 * 4
coeff = pca(ingredients)
Output:
coeff = 4×4
-0.0678 -0.6460 0.5673 0.5062
-0.6785 -0.0200 -0.5440 0.4933
0.0290 0.7553 0.4036 0.5156
0.7309 -0.1085 -0.4684 0.4844
I am wondering can i change it to output of 13 *2
Matlaberhttps://fr.mathworks.com/matlabcentral/profile/authors/9926819-matlabertag:fr.mathworks.com,2005:Question/4454142019-02-17T14:02:34Z2019-02-19T21:56:46ZCan Speeded up robust feature detect interest point from binary image on only black pixel?Can Speeded up robust feature detect interest point from binary image on only black pixel?Ömerhttps://fr.mathworks.com/matlabcentral/profile/authors/2666501-omertag:fr.mathworks.com,2005:Question/4459032019-02-19T21:25:00Z2019-02-19T21:55:10ZHow to optimize experimental data to measured reference signal?Hello,
I would like to use the optimization toolbox for the following task.
I have a reference signal, lets call it RefSignal which is array of doubles. Moreover, I have an array with experimental data, lets call that ExpSignal. I know from the theory that the sum of two different shifted RefSignal results in ExpSignal. Refsignal and ExpSignal are equally long.
I would like to achieve an optimization alogrithm which minimize an error function:
I thougt of something like this
ErrFunc=ExpSignal-param(1).*(circshift(RefSignal,-param(2))+circshift(RefSignal,param(2)))
Whereas, param includes the optimize parameter namley param(1) the amplitude and param(2) the shift itself.
I achieved results using fminsearch which needs the theoratical function RefSignal. However, the experimental data are not that ideal why I would like to use the measured RefSignal. It is working manually by changing each param individually but I would like to automize the whole process.
How can I minimize the error function when only sampled signals are given ?
Pawlhttps://fr.mathworks.com/matlabcentral/profile/authors/10118070-pawltag:fr.mathworks.com,2005:Question/4453682019-02-17T04:35:06Z2019-02-19T21:49:22ZHow to split data in reference to certain values from one column and organise into a cell array?- The logical indices in position 1 contain a true value outside of the array bounds. ERRORI have a large data selection of 1037803 points for each test and 3 repeats. The data has 12 columns that indicate various different parameters. Column 6 indicates the speed of which the test ran. In total there was 100 different speeds. The first speed is 31.4159261390256 and then it increases by 31.4159 each time up to the last speed of 3141.59. Therefore, i want to split the data into a cell array that includes 100 rows, one for each speed with the data for each test next to it.
I have used this;
for n= 0:100 % 100 different speeds
ans = n;
indexes=((New_Data{1,1}(:,6)> (31+31.4159*n)& (New_Data{1,1}(:,6)<(32.4159+31.4159*n))) ) ; %values are not completly fixed and change by some degree
speeds{n+1,1} = num2str(31+31.4159*n); %first column = the speed values
speeds{n+1,2} = New_Data{:,1}(indexes,:); %test 1
speeds{n+1,3} = New_Data{:,2}(indexes,:); %test 2
speeds{n+1,4} = New_Data{:,3}(indexes,:); %test 3
end
This works well untill New Data {:,3} for the last speed, where it appears blank (figire 1) . I have checked my data and the data is same length and has the final speed so the original data is defo not the issue (figure 2).
I keep getting the following error.
The logical indices in position 1 contain a true value outside of the array bounds.
Error in dat_proc2 (line 58)
speeds{n+1,4} = New_Data{:,3}(indexes,:);
But if i just look at data 3 (test 3) alone it seems to work but as soon as i look at it with the other 2 tests i get this error.
I think it may be the indexing. If anyone can help me solve this problem that would be great.
Sufia Fatimahttps://fr.mathworks.com/matlabcentral/profile/authors/12508175-sufia-fatimatag:fr.mathworks.com,2005:Question/4455312019-02-18T09:08:02Z2019-02-19T21:33:10Zhelp with ode solvers non-linear ode 1st law of thermodynamicsHello all:
I am trying to solve the ODE's:
d2y/dt2=-g+(P-Pa)*Ap
dP/dt=k*P*((1/m) *(dm/dt) - (k/(L+y))*(dy/dt))
dm/dt=(m/V) [q-c*Ao*(Pa/P)^(1/k) * {2*k/(k-1) * P*V/m *(1-(Pa/P)^((k-1)/k))}^0.5
V(y)=Ap*(L+y)
where w,Ao,q,Ap,Pa,k,L,g are all constants. but P(t),m(t), y(t) are functions of t
I wrote the following M-file but it looks like it's not working for the m variable. Is there anyting wrong with code or state space variable?
##############################################
clear;close all
global Pa;global A;global Wp;global q;global Ao,global c;global L;global k;
Pa=101000;
d=.05;
Wp=7;
q=2;
Ao=0.01;
c=.1;
L=0.75;
k=1.4;
Te=300;
A=0.25*pi*d^2;
mass=(Pa*L*A)/(287*Te);
tic
W=200;
tf=10;
Fs = .1; %sampling rate
Ts = 1/Fs; %sampling time interval
tspan =0:Fs:tf; %sampling period
y0=[0,.0,101000,mass];
[t,y]=ode45(@Sample01,tspan,y0,[]);
%y[YfreqDomain_d,frequencyRange_d]=positiveFFT(y(:,1),Fs);
subplot(2,2,1);plot(t,y(:,1),'k');
subplot(2,2,2);plot(t,y(:,2),'k');
subplot(2,2,3);plot(t,y(:,3)/Pa,'k');
subplot(2,2,4);plot(t,y(:,4),'k');
dlmwrite('tssst',[y]);
toc
HERE IS THE FUNCTION OF STATE SPACE
function y_dot=Sample01(t,y)
global Pa;global A;global Wp;global q;global Ao,global c;global L;global k;
y_dot=zeros(4,1);
y_dot(1)=y(2);
y_dot(2)=-Wp*9.81/Wp+(y(3)-Pa)*A/Wp;
y_dot(3)=y(3)*((k/y(4))*y_dot(4)-(k/(L+y(1)))*y(2));
y_dot(4)=y(4)/(L+y(1))*(q-c*Ao*(Pa/y(3))^(1/k)*((2*k/(k-1))*y(3)*(L+y(1))/y(4)*(1-(Pa/y(3))^((k-1)/k)))^0.5);
Ahmed S. Sowayanhttps://fr.mathworks.com/matlabcentral/profile/authors/8027473-ahmed-s-sowayantag:fr.mathworks.com,2005:Question/4459042019-02-19T05:00:00Z2019-02-19T21:29:02ZHow do I see the full list of licenses within my MathWorks Account?How do I see the full list of licenses within my MathWorks Account?
MathWorks Support Teamhttps://fr.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:fr.mathworks.com,2005:Question/4458922019-02-19T19:49:07Z2019-02-19T21:24:24ZHow does fread bring in a signed integer?Hello,
I am working with the reading in of binary files and I had a question on the fread function.
Basically, the datagram format specifies that the data samples are stored as signed 16bit integer (2's compliment). From looking around, there are a number of methods for handling signed numbers (2's compliment, 1's compliment, signed magnitude, offset...). So when i use fread() as follows:
s = fread(fid,256,'int16',0,'b');
Are the numbers read in as 2's compliment binary, or signed magnitude, or something else? I have to image it matters but I can't find what method MATLAB uses.
Thanks for any and all help!Mikehttps://fr.mathworks.com/matlabcentral/profile/authors/8387728-miketag:fr.mathworks.com,2005:Question/4455362019-02-18T09:51:20Z2019-02-19T21:12:21Zhow to choose the number in a random mannerA=[1 2 ;
4 5 ;
7 8 ;
10 11;
12 13;
14 15;
16 17 ;
18 19]
G=size(A,1)
C=1:G
Could anyone help me how to choose the number in C in a random manner,such that C can be 2 or 3 or 4 or 5 or 6.jaah navihttps://fr.mathworks.com/matlabcentral/profile/authors/11695462-jaah-navitag:fr.mathworks.com,2005:Question/4458982019-02-19T20:29:00Z2019-02-19T21:11:27ZI can't find where the mistake is. Could anyone help me with my code?Differential equation of simple pendulum
d^2θ /dt^2 + (g/L)*sin(θ )=0
Initial conditions: θ(0) = θ0 , θ'(0) = 0
The angular displacement θ0 = 30 degrees, length of the pendulum L = 0.6 m and gravity g = 9.82 m/s^2.
This is the script I use to solve the differential equation with ode45 and to plot the solution in degrees but I got a wrong plotting.
theta0=30;
L=0.6;
g=9.82;
t=0:100;
[t,theta30]=ode45(@(t,THETA) fun(t,THETA,g,L),t,[theta0*pi/180 0]);
plot(t,theta30(:,1)*180/pi,'--b')
grid on
axis ([0 t(end) -30 30])
xlabel('Time')
ylabel('Angle')
function dthetadt=fun(t,THETA,g,L)
dthetadt=zeros(2,1);
dthetadt(1)=THETA(2);
dthetadt(2)=(-g/L)*sin(THETA(1));
end
DShttps://fr.mathworks.com/matlabcentral/profile/authors/14043820-dstag:fr.mathworks.com,2005:Question/3755022018-01-04T05:14:22Z2019-02-19T21:10:58ZMy convolutional network doesn`t learn properly. Can someone explain why and give me some advice?Hi everyone, I`m pretty new at neural network, and I`m trying to make learn my cnn. From a set of about 15000 images i made a training set (70% using random images) and 30% as validation set. The problem is I usually get this kind of graph:
As you can see, the validation star to diverge and it can`t learn anything more. I tried various training options, actually I`m using Max Epochs at 70, validation frequency at 100 (tried with 30 and 50), initial learn rate set at 0.01 with a learn rate drop factor of 0.1; the learn rate drop period is about 15 (tried with different settings; 3, 5, 7, 10....) and my minibatch size is 60. I tried different layer configurations but I`m showing you the actual one. The num_clases value is 120 because it`s the number of different classes I`m trying to classify. Anyone can give me a hint what I`m doing wrong or which changes should I do to make it work properly?
layers = [
imageInputLayer([128 128 3])
convolution2dLayer(5,64,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(5,128,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,64,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,128,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,256,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(3,512,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(1,64,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(1,128,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(1,256,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
convolution2dLayer(1,512,'Padding',1)
batchNormalizationLayer
reluLayer
maxPooling2dLayer(2,'Stride',2)
dropoutLayer
fullyConnectedLayer(2000)
dropoutLayer
fullyConnectedLayer(2000)
fullyConnectedLayer(num_clases)
softmaxLayer
classificationLayer];Joaquin Carrascohttps://fr.mathworks.com/matlabcentral/profile/authors/11522939-joaquin-carrascotag:fr.mathworks.com,2005:Question/4457862019-02-19T10:38:44Z2019-02-19T21:08:44Zhow to find the index for the following code
If A=1:10,%A= 1 2 3 4 5 6 7 8 9 10
But I want to display the index of A using for loop.
Could anyone help me to solve the issue.
jaah navihttps://fr.mathworks.com/matlabcentral/profile/authors/11695462-jaah-navitag:fr.mathworks.com,2005:Question/4458582019-02-19T17:07:12Z2019-02-19T21:07:02ZHow do I add specific columns by interpolation in a time series matrix data?Hello, humble greetings. Please I have a time series data of monthly deformations from January 2005 to December 2015, an 82 by 119 matrix (attached above in .mat format named VC), which in actual fact should have been a matrix of 82 by 132. However, the entire data for some months (columns) are missen, which include, 2011/1, 2011/6, 2012/5, 2012/10, 2013/3, 2013/8, 2013/9, 2014/2, 2014/7, 2014/12, 2015/5, 2015/6, 2015/10, and 2015/11 as seen in the attached time (in .mat format named T2,) for the 82 by 119 matrix. My challange now is how to add data for each of these missen months by interpolation at their respective columns. each column reprsents data for a month (example, first column is for january 2005, second column is for february 2005 in that order to December 2015). I would appreciate your guide and help.
Thank you. Abubakar Sani-Mohammedhttps://fr.mathworks.com/matlabcentral/profile/authors/14355833-abubakar-sani-mohammedtag:fr.mathworks.com,2005:Question/4458972019-02-19T20:21:57Z2019-02-19T21:05:38ZDetect Vertical Lines without using functionI would like to apply the following masks to the image. The masks should detect lines at various angles.
This is currently implemented using the imfilter function. How can I implement this without using imfilter (or any other built-in funciton)?
clc
clear all
horizontalKernel = [-1,-1,-1;2,2,2;-1,-1,-1];
verticalKernel = [-1,2,-1;-1,2,-1;-1,2,-1];
diagUpKernel = [-1,-1,2;-1,2,-1;2,-1,-1];
diagDownKernel = [2,-1,-1;-1,2,-1;-1,-1,2];
building=imread('https://www.red-current.com/images/article_images/thermal_image_building.jpg');
figure;
horizontalBuilding = imfilter(building, horizontalKernel);
subplot(2,2,1), image(horizontalBuilding);
verticalBuilding = imfilter(building, verticalKernel);
subplot(2,2,2), image(verticalBuilding);
diagDownBuilding = imfilter(building, diagDownKernel);
subplot(2,2,3), image(diagDownBuilding);
diagUpBuilding = imfilter(building, diagUpKernel);
subplot(2,2,4), image(diagUpBuilding);SBakchttps://fr.mathworks.com/matlabcentral/profile/authors/14737531-sbakctag:fr.mathworks.com,2005:Question/4453522019-02-16T23:39:23Z2019-02-19T20:49:21Zfft definition in matlab doc puzzlingHi all,
I'm a bit puzzled with the definition of fft in the documentation :
https://fr.mathworks.com/help/matlab/ref/fft.html
The definition at the very end in "more about" states the fft as a projection on positive frequency (from 0 to Fs/N) while the examples suggest a "two sided" spectrum ie. with positive frequencies and negative ones (-Fs/2 to Fs/2).
To make my question more precise :
the definition in the doc is :
Given that the fft results in both positive and negative frequencies, I woumld have guess a defintion like :
Am I missing something ?
thanks in advance for your help,
Francois.françois anquezhttps://fr.mathworks.com/matlabcentral/profile/authors/4945435-francois-anqueztag:fr.mathworks.com,2005:Question/4457822019-02-19T10:25:21Z2019-02-19T20:43:26Zhow to find the indexing for the following code.clear all;
clc
A=[1 2;
3 4;
5 6;
7 8;
9 10;
11 12;
13 14;
15 16];
C=size(A,1)
B=1:3
D= randi(C,1)
I want to perform the randi(C,1) with respect to 1st index of B followed by 2nd index ,then 3rd index.
Could anyone please help me on this.
jaah navihttps://fr.mathworks.com/matlabcentral/profile/authors/11695462-jaah-navitag:fr.mathworks.com,2005:Question/907342013-10-19T09:10:27Z2019-02-19T20:42:23ZSOLVING PDES USING RBF ?I WNAT PDES PROBLEM USING RBF MATLAB CODE
robabehhttps://fr.mathworks.com/matlabcentral/profile/authors/4719356-robabehtag:fr.mathworks.com,2005:Question/4444692019-02-12T06:02:40Z2019-02-19T20:40:05ZI want to add two pulse generator in simulink and dump it into arduino uno...the result i am getting is change in the frequency at arduino output what i have set in pulse generator?
i want to generate 0.02 (50 hz) time period pulse by adding this two pulse generator, i am getting the output from the arduino but frequncy is not 50 hz, kindly suggest
this is the pulse i want to generate at arduino output for 0.02 time period.
Aniket Manjarehttps://fr.mathworks.com/matlabcentral/profile/authors/12110619-aniket-manjaretag:fr.mathworks.com,2005:Question/4459002019-02-19T20:38:56Z2019-02-19T20:38:56ZCan we create a narxnet type network with more than one external inputs I am trying to train a time series using narxnet, where I have to use multiple time series as external inputs. When I try to train the network I get the followng error.
Number of inputs does not match net.numInputs.
Here the numInputs property is set to 2 by default in matlab. Is it possible to change this net.numInputs property to a value greater than twoIroshani Jayawardenehttps://fr.mathworks.com/matlabcentral/profile/authors/5608782-iroshani-jayawardenetag:fr.mathworks.com,2005:Question/975582011-04-21T22:12:00Z2019-02-19T20:29:22ZWhy do I receive License Manager Error -97? ERROR: License Manager Error -97.
The desired vendor daemon is down.
Check the lmgrd log file, or try lmreread.
Feature: MATLAB
Vendor:Host: hostname
License path: C:\Program Files\MATLAB\bin\win32\license.dat;
D:\Program Files\MATLAB\bin\win32\*.lic
FLEXnet Licensing error: -97,121
For Further information, refer to the FLEXnet Licensing End User Guide, available at "www.macrovision.com".
For more information, see MathWorks Support page at <http://www.mathworks.com/support> and search for
"license manager error -97"
MathWorks Support Teamhttps://fr.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:fr.mathworks.com,2005:Question/4457602019-02-19T09:25:00Z2019-02-19T20:26:21ZHow to solve this error when using PSOGWO to optimize an objective function?When I run the code of PSOGWO to optimize the following function :-
function f = simple_fitness_two_layers(x)
load gh2b.mat;load obs.mat;
%where :-
r=[58.3095 76.1577 86.0233 98.9949];
r0=mean(r);zx=[30 30 70 70];s=0;
for ii=1:length(r);
s=s+(abs(r(ii)-r0)./4);
end
Phim=s./(zx);
f=norm(gh2b*x(:)-obs,2)+20*Phim;
%and gh2b is : 12*30 matrix and obs is 12*1 vector
The following error:-
Operands to the || and && operators must be convertible to logical scalar values.
Error in PSOGWO (line 38)
if fitness>Alpha_score && fitness<Beta_score
Error in main (line 25)
[Best_score,Best_pos,PSOGWO_cg_curve]=PSOGWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
>> M.Shaarawyhttps://fr.mathworks.com/matlabcentral/profile/authors/11317174-m-shaarawytag:fr.mathworks.com,2005:Question/4434832019-02-06T11:02:59Z2019-02-19T20:20:15Zsimulink toolbox matlap onlineHi . i'm using matlap on the internet . i can not find the simulink toolbox ?Hind Alqhtanihttps://fr.mathworks.com/matlabcentral/profile/authors/14705859-hind-alqhtanitag:fr.mathworks.com,2005:Question/4458812019-02-19T18:49:50Z2019-02-19T20:14:18Zdlmwrite with text and numbersI am wanting to transfer data that is input into a UI to a csv file. I am using dlmwrite currently but keep running into the issue of the csv not functioning properly. Dlmwrite is outputting nonsense text, and I frankly am lost on what to try. I've done all I know how to do.Daelyn Greenehttps://fr.mathworks.com/matlabcentral/profile/authors/7217469-daelyn-greenetag:fr.mathworks.com,2005:Question/4457502019-02-19T08:20:55Z2019-02-19T20:13:05ZHow to fix this error in "for" loop?Hi,
I need to find the Y value that corresponds to the maximum X value for the curves attached herewith.
I tried to use interp1, but I am not sure how to make it for several files.
I tried to develop this code, but it does not work.
I get the following error message:
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in ResidualDisp (line 10)
maxy = matDrift(max(matDrift(:,1)),2);
The code:
clear; clc;
Folder = cd;
N=10;
for k = 1:N;
Driftt = sprintf('X%d.out', k);
matDrift = importdata(fullfile(Folder, Driftt));
maxy = matDrift(max(matDrift(:,1)),2);
endIsmail Qeshtahttps://fr.mathworks.com/matlabcentral/profile/authors/10292327-ismail-qeshtatag:fr.mathworks.com,2005:Question/4447312019-02-13T11:33:56Z2019-02-19T20:09:14Zcalculating x when y is > 0Hello
I have plotted a changing distance (d(x)) with time using cftool and calculated the function. Its derivative was calculated and this is v(x). when plotted with fplot the initial Y values are 0. I am calculating the x position at which this rises above the x axes (y>0). To do this i made v(x) equivalent to 1 (==1) and evluated x yet:
>>v(x)==1
ans =
(4119*x^2)/10000 - (1787*x)/5000 + 891/2500 ==1
>> eval x
x =
x
Will someone please help to calculate this? i can measure the x value directly. It is preferable to standardise this procedure.
GS.Gavin Seddonhttps://fr.mathworks.com/matlabcentral/profile/authors/6295967-gavin-seddontag:fr.mathworks.com,2005:Question/4456782019-02-18T22:21:24Z2019-02-19T20:07:18ZHow to solve diffusion equation in spherical coordinate using Matlab?PDE toolbox in Matlab expects the equations in Cartesian coordinate. In this page it says what the general shape of the equations should be: https://nl.mathworks.com/help/pde/pde-coefficients.html
that is:
I want to solve the diffusion equations:
Thus, in my case m, a, and f are zero. If we are in Cartesian coordinate then d is one and c, the diffusion constant, is for example 0.001. However, I want to solve the equations in spherical coordinates. Here is a link to Laplacian in spherical coordinate:
http://mathworld.wolfram.com/LaplacesEquationSphericalCoordinates.html
How can I solve the diffusion equation in the spherical coordinates in Matlab? or How can I determine the matrix of coefficienct "c" in spherical coordinates?Yasharhttps://fr.mathworks.com/matlabcentral/profile/authors/4477665-yashartag:fr.mathworks.com,2005:Question/4273092018-11-01T00:40:50Z2019-02-19T20:01:02ZClassify requires at least 3 argumentsHi,
I am having trouble when trying to use the "classify" function to evaluate the performance of my neural network.
I am using the following code:
net = load('mynet.mat'); %this returns my previsouly trained SeriesNetwork object
test_folder = './test_data';
test_images = imageDatastore(test_folder,'FileExtensions','.jpg');
[Y,scores] = classify(net,test_images);
But the classify function throws me an error that it requires at least 3 arguments, which means it is trying to use the classify function from the statistics package.
What can I make do force the use of the classify from the deep learning package?
Thanks,
RaphaelRaphael Ruschelhttps://fr.mathworks.com/matlabcentral/profile/authors/5285189-raphael-ruscheltag:fr.mathworks.com,2005:Question/4458952019-02-19T20:00:46Z2019-02-19T20:00:46ZAccessing the Tunable Parameters of a BlockHello,
I am using Matlab R2017b . Normally I would right-click on the subsystem block in my model and Select C/C++ Code-> Generate S-Function. A window would pop up asking me to select which parameters should be tunable. How do I access that list of tunable parameters via command line? I would like to be able to perform the above via script. Christopher Kujawinskihttps://fr.mathworks.com/matlabcentral/profile/authors/14513936-christopher-kujawinskitag:fr.mathworks.com,2005:Question/3865962018-03-06T11:10:07Z2019-02-19T19:59:34ZHOW TO INSTALL SHEARLET TOOLBOX IN MATLABI have to install shearlet toolbox in matlab?I have downloaded but i dont know to install it? ponnu kunnathhttps://fr.mathworks.com/matlabcentral/profile/authors/12278876-ponnu-kunnathtag:fr.mathworks.com,2005:Question/4458932019-02-19T19:51:32Z2019-02-19T19:51:32Zcomparing two 3d scatter chartsIm new to matlab so excuse my lack of knoweldge. Im trying to compare two 3d scatter graphs. As you can see in the attached picture they are golf swings. im trying to find the best way to compare them
my matlab code is pretty simple for the output
data = csvread('new.csv',1);
figure
hs(1) = subplot(2,1,1);
hs(2) = subplot(2,1,2);
x= data(:,2);
y= data(:,3);
z= data(:,4);
scatter3(hs(1),x,y,z, 'b', 'filled');
data1 = csvread('new3.csv',1);
x1= data1(:,2);
y1= data1(:,3);
z1= data1(:,4);
scatter3(hs(2),x1,y1,z1, 'r', 'filled');Daniel Harperhttps://fr.mathworks.com/matlabcentral/profile/authors/14611728-daniel-harpertag:fr.mathworks.com,2005:Question/3211072017-01-19T16:12:17Z2019-02-19T19:48:05ZAdding new values in between existing values in an arrayI have 5 arrays with four values in each of them. Longitude array, Latitude Array, Velocity U array, Velocity V array and a time array in datenum form. This is ocean current data, and I want to simulate a ship moving through four values in 10 second intervals. So its like adding 360 points new datenum values between each datenum in the time array. So since the time array will increase if I did that. I would have to do something similar to the other arrays, but keep them the same length as the time array. That way i will be able to plot them. Since the velocity will not be in ascending order, how can fill the points in between each value. SO basically i want to make new points that coincide with the actual points.
Below I kind of tried to type what I want my code to do.
tarray: 4x1 single
lon: 4x1 double
lat: 4x1 double
u: 4x1 double
v: 4x1 double
after adding 10 seconds in between datenums
tarray: 1440x1 single
lon: 1440x1
lat: 1440x1
u: 1440x1
v: 1440x1
I'm not sure how to do this and I have been looking into it. If someone could help me progress into my study that would be great!
Sancheet Hoquehttps://fr.mathworks.com/matlabcentral/profile/authors/6993993-sancheet-hoquetag:fr.mathworks.com,2005:Question/4452462019-02-16T00:52:49Z2019-02-19T19:47:23ZConditionally Defining a Variable using ODE45How could I take this code I'm using and conditionally define my variable 'p'? For example, I want p=0 everywhere except when 3<t<4, then I want p=1.2. Here is my code:
tspan=[1 7];A0=1;P0=1;g=1;p=0;B=0.15;
[t,x] = ode45(@(t,x) [-g*x(1) + p*x(1); -x(1)*x(2)+ B*x(2)], tspan, [A0 P0]);Thomas Veithhttps://fr.mathworks.com/matlabcentral/profile/authors/13550529-thomas-veith