https://it.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2019-02-19T08:43:53Ztag:it.mathworks.com,2005:Question/4457502019-02-19T08:20:55Z2019-02-19T08:43:53ZHow 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://it.mathworks.com/matlabcentral/profile/authors/10292327-ismail-qeshtatag:it.mathworks.com,2005:Question/4453122019-02-16T15:59:30Z2019-02-19T08:43:21ZMATLAB crashing when plotting with AMD driverseven after updating the drivers MATLAB is crashing.
pvr murthyhttps://it.mathworks.com/matlabcentral/profile/authors/14745717-pvr-murthytag:it.mathworks.com,2005:Question/4456172019-02-18T17:12:38Z2019-02-19T08:41:14ZHow 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://it.mathworks.com/matlabcentral/profile/authors/14363488-hiruni-gunawardhanetag:it.mathworks.com,2005:Question/4457202019-02-19T05:04:33Z2019-02-19T08:39:05ZParse error: The expression to the left of the equals sign is not a valid target for an assignment.Hi every body
I have been used Mathlab Fun to sort ten values. but I get error
Parse error: The expression to the left of the equals sign is not a valid target for an assignment.
Please let us know what is the error description.
function B = selectionSort( Vc, Vc1, Vc2, Vc3, Vc4, Vc5, Vc6, Vc7,Vc8,Vc9)
{
A=[ Vc Vc1 Vc2 Vc3 Vc4 Vc5 Vc6 Vc7 Vc8 Vc9]
B : sort(A)
}Arkanra Kadhumhttps://it.mathworks.com/matlabcentral/profile/authors/542959-arkanra-kadhumtag:it.mathworks.com,2005:Question/4195962018-09-18T14:02:42Z2019-02-19T08:37:44Z14.2 Project - Stellar Motion (Script). Can someone please help me with task 3 of the onramp? I've been trying to figure it out for hours!!! But I just can't seem to get it! I even tried the solution but it doesn't work....Maryam AlKhouryhttps://it.mathworks.com/matlabcentral/profile/authors/13544226-maryam-alkhourytag:it.mathworks.com,2005:Question/4122852018-07-26T18:03:13Z2019-02-19T08:37:33Z14.2 Project - Stellar Motion (Script). Can someone please help me with task 3 of the onramp?I dont understand what to do can someone please explain and help me?Peet Visserhttps://it.mathworks.com/matlabcentral/profile/authors/13082072-peet-vissertag:it.mathworks.com,2005:Question/937192009-06-27T01:11:00Z2019-02-19T08:35:46ZWhy does the formatting of my Y-axis tick labels change to exponential format when I plot my data?I am plotting x and y data as follows:
x = [1 2 3]
y = [10000 20000 30000]
plot(x,y)
However, once the figure is plotted the Y-axis tick labels are in exponential format 1 ,2 ,3 e+4 . I want the Y-axis tick labels to be in the same format as my original 'y' vector (i.e. 10000, 20000, etc.).MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:it.mathworks.com,2005:Question/4457522019-02-19T08:34:39Z2019-02-19T08:34:39ZI have combined the Wind Turbine Doubly-Fed Induction Generator (Phasor Type) with the power_PVarray_250kW model to create a small microgrid model. While running the simulation model i get the error. Error while runing the simulink file is:
The "FixedStepDiscrete" solver cannot be used to simulate block diagram 'power_PVarray_250kW' because it contains continuous states.
I have combined the Wind Turbine Doubly-Fed Induction Generator (Phasor Type) with the power_PVarray_250kW model to create a microgrid. After all the connections i get the above error. I need to know where this "FixedStepDiscrete" solver is used in the model and how can i correct it to run my model successfully.
Attached is the simulink file for the model that i have created.Muhammad Zubairhttps://it.mathworks.com/matlabcentral/profile/authors/14602873-muhammad-zubairtag:it.mathworks.com,2005:Question/4457512019-02-19T08:32:59Z2019-02-19T08:32:59ZHow to read matfile from guide Dear all,
I have a mat file that consist of timetable data of 705 x 3
I created a button using Guide
Now i want to load this data in matlab workspace as well as store teh data in a variable say S.
I gave the follwing code in call back
load sensorlog_20190126_101635.mat
but not getting the variable loaded
Chandra Bhushanhttps://it.mathworks.com/matlabcentral/profile/authors/14127046-chandra-bhushantag:it.mathworks.com,2005:Question/4455272019-02-18T08:36:28Z2019-02-19T08:31:26ZDetect all the rectangles in imageHey all,
in the following image, all the rectangles are a little bit deformed due to power leakage effect. I want to detect all the rectangles and obtain the positions of the rectangles.
Is there a way to detect all rectangles?
Thank yousimon xuhttps://it.mathworks.com/matlabcentral/profile/authors/14242564-simon-xutag:it.mathworks.com,2005:Question/4446322019-02-12T22:09:33Z2019-02-19T08:28:43Z3D plot for pricing options over increasing time and asset priceI have a function that works out the black scholes formula over changing time and price of the underlying.
I need C to store and save the answer for each iteration, in vector form, in order to plot a 3D to show the price of the call option changing over time and increasing underlying price.
S0=100;
X=120;
r=0.1;
sigma=0.2;
N=50;
x1=linspace(0,0.5,N); %time in years
x2=[0:1:N]'; %price of the underlying
C=zeros(1,N);
for x2=0:N
for x1=0:N
d1=(log(x2/X)+(r+0.5*sigma.^2)*x1)/(sigma*sqrt(x1));
d2=d1-sigma.*sqrt(x1);
C=S0*normcdf(d1)-X*exp(-r*x1)*normcdf(d2)
end
end
Katie Brewerhttps://it.mathworks.com/matlabcentral/profile/authors/13881491-katie-brewertag:it.mathworks.com,2005:Question/4457462019-02-19T08:05:44Z2019-02-19T08:28:09ZCut a .JPG imageHi everybody,
i would like to cut a .JPG image. To do this i used that script but it does not run:
X=imread('C:\Users\Utente\Desktop\DSC_0183.JPG');
[columns,rows,colors]=size(X);
X2 = imcrop(X,[400, 1, rows-400, columns]);
imshow(X2)
With X=my image and X2=new image
and 400, 1=coordinates of the upper left corner of the specified rectangle
and rows-400, columns= coordinates of the bottom right corner of the specified rectangle.
In particular the image (X2) is correctly cut to the left but not to the right. How can i resolve it?
Thank you!!
Riccardo Rossihttps://it.mathworks.com/matlabcentral/profile/authors/14456118-riccardo-rossitag:it.mathworks.com,2005:Question/4451102019-02-15T08:47:47Z2019-02-19T08:27:43Zskin tone detection matlab program in ycbcr and hsv colour models.we are doing a project on skin detection in an image. we want matlab code for skin detection in ycbcr and hsv colour models . If the pixel is in the range of skin then should be remained same otherwise it should be masked with black colour.leela gandihttps://it.mathworks.com/matlabcentral/profile/authors/14680487-leela-ganditag:it.mathworks.com,2005:Question/4456162019-02-18T16:43:57Z2019-02-19T08:27:30Z row wise Inner product of two matrices without using loopI have two matrices A= 40 x 50 and B = 61 x 50. I want to get the row wise dot product for the entire combination of rows of two matrices. Using for loop it is something like this
for i=1:40
for j=1:61
inner_prod(i,j) = dot (A(i,:),B(j,:);
end
end
Is there any way to do this avoiding the for loop and less execution time ?sandeep pandeyhttps://it.mathworks.com/matlabcentral/profile/authors/7793402-sandeep-pandeytag:it.mathworks.com,2005:Question/4455422019-02-18T10:38:03Z2019-02-19T08:26:45ZCompare two or more cell arrays with a specific tolerence?Hi.
I have a cell array with length 3 :
M_t={{[0,1],[0 0 2]},{[0,1.01],[0 0 2]},{[0,1],[0 .001 2]}};
I want to compare these 3 arrays with a specific tolerence. How can i do this?
I have tried intersect before.
Thanks.
Najmeh Eskandarihttps://it.mathworks.com/matlabcentral/profile/authors/12493981-najmeh-eskandaritag:it.mathworks.com,2005:Question/2669692016-02-07T08:21:07Z2019-02-19T08:25:48ZCombine two matrices (every other column)I have two matrices A and B which are for example
A=[1 2 3;4 5 6; 7 8 9] and B=[10 11 12; 13 14 15; 16 17 18]
And I would like to combine these matrices so that every other column is from A and every other is from B. So the answer should be matrix:
[1 10 2 11 3 12; 4 13 5 14 6 15; 7 16 8 17 9 18]
Of course my matrices are not only 3x3 matrices but n x n matrices.
My history with Matlab is so short that I don't figure out if that is even possible to do?Snowfallhttps://it.mathworks.com/matlabcentral/profile/authors/7587828-snowfalltag:it.mathworks.com,2005:Question/3537582017-08-23T10:57:10Z2019-02-19T08:25:21ZMatlab Beep at zooming in plot and evaluating variablesI recently started noticing that, when clicking zooming buttons in a plot, matlab starts producing 'error' beeps.
However, no error is printed to the command window, and also the zooming works without any problems.
I experience the same while in the variable editor and double clicking fields of a struct (to open them). This constant beeping is slowly driving me crazy and as of yet i have not been able to find what's causing it.
I already found: <https://nl.mathworks.com/matlabcentral/answers/84916-how-to-disable-beep-beep-off-does-not-work?s_tid=srchtitle How to disable beep>
but that turns it off if a delimiter is incorrect during coding, which is not when I hear the beeps.
Can anyone tell me what is causing these beeps and perhaps even better, how to turn them off?
Robbin van Hoekhttps://it.mathworks.com/matlabcentral/profile/authors/1955995-robbin-van-hoektag:it.mathworks.com,2005:Question/4457402019-02-19T07:25:15Z2019-02-19T08:25:14ZHow to match the matrix dimension ?clc
clear all
close all
load ('C:\Users\manish\Downloads\100ml.mat')
val=val';
plot(val)
I=val((1:end),1);
str1=dec2bin(typecast(int8(I),'uint8'));
ecg_signal_I=filtering(I);
c1=dec2bin(typecast(int8(ecg_signal_I),'uint8'));
figure
title('I')
plot(ecg_signal_I)
ylim([-1000 1000])
sampling_frequency = 360;
mains_coeff = 0.1; % Amplitude of mains line to change. Depends on your ECG signal.
time_step = 1/sampling_frequency;
max_time = 2; % Duration of your signal in seconds.
t = time_step:time_step:max_time; % This is our time vector.
mains_signal = cos(2*pi*110*t); % 110Hz mains frequency. Depends.
dirty_signal = val' + mains_coeff*mains_signal;
plot(dirty_signal);
I am getting error in second last line of the above code: Matrix dimensions must agree.
Error in c100ml2 (line 21)
dirty_signal = val' + mains_coeff*mains_signal;manish kumarhttps://it.mathworks.com/matlabcentral/profile/authors/12904403-manish-kumartag:it.mathworks.com,2005:Question/4395232019-01-13T00:00:53Z2019-02-19T08:21:40ZProblem with dbstop if error in 2018bAfter downloading Matlab 2018b, I started having the following problem using the command dbstop if error:
My code will stop at the error as usual but then at some point later as I am debugging (typing variable names in the command line to check their values, etc.), the debugger will stop at line 43 of getArrayEditorBrushCache which reads:
eval(['I = I' subsstr ';']);
Then I have to type dbclear if error to escape the debugger and start my program over.
This is happening to me in many of my programs where dbstop if error was working fine in previous versions of Matlab. Any ideas for how to solve this or is this just a new bug? JWallhttps://it.mathworks.com/matlabcentral/profile/authors/4947838-jwalltag:it.mathworks.com,2005:Question/4456092019-02-18T16:20:45Z2019-02-19T08:21:08ZHow to calculate sum of all the possible combinations of two vector elementsI have two vectors A and B with different lengths. The B vector always have 4 elements. How can I obtain the vector C containing sum of all the possible combinations of elements of B vector with A.
For example B= [1 2 3 4] and A= [0.1 0.2 0.3 0.4 0.5 0.6]
Then C= [1.1 1.2 1.3 1.4 1.5 1.6 2.1 2.2 2.3 2.4 2.5 2.6 3.1 3.2 3.3 3.4 3.5 3.6 4.1 4.2 4.3 4.4 4.5 4.6]
Thank youDavoudhttps://it.mathworks.com/matlabcentral/profile/authors/3867523-davoudtag:it.mathworks.com,2005:Question/4456002019-02-18T15:48:44Z2019-02-19T08:17:46ZWarning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. I have coding such as this:
En = length(n); % n = number of data tottaly
Ex1= sum(x1); % Ex1= number of Depth
Ex2= sum(x2); % Ex2= number of Amax
Ex3= sum(x3); % Ex3= number of Mw
Ex4= sum(x4); % Ex4= number of Vs
Ex5= sum(x5); % Ex5= number of Distance
x1x2= dot(x1,x2);
x1x3= dot(x1,x3);
x1x4= dot(x1,x4);
x1x5= dot(x1,x5);
Ex1x2=sum(x1x2);
Ex1x3=sum(x1x3);
Ex1x4=sum(x1x4);
Ex1x5=sum(x1x5);
x1_2 = x1.^2;
x2_2 = x2.^2;
x3_2 = x3.^2;
x4_2 = x4.^2;
x5_2 = x5.^2;
Ex1_2 = sum(x1_2);
Ex2_2 = sum(x2_2);
Ex3_2 = sum(x3_2);
Ex4_2 = sum(x4_2);
Ex5_2 = sum(x5_2);
Ey1=sum(y1);
x1_y1=dot(x1,y1);
x2_y1=dot(x2,y1);
x3_y1=dot(x3,y1);
x4_y1=dot(x4,y1);
x5_y1=dot(x5,y1);
Ex1_y1=sum(x1_y1); %Ex1_y = number x1 multiplyied y
Ex2_y1=sum(x2_y1); %Ex2_y = number of x2 multiplied by y
Ex3_y1=sum(x3_y1);
Ex4_y1=sum(x4_y1);
Ex5_y1=sum(x5_y1);
A = [En Ex1 Ex2 Ex3 Ex4 Ex5;Ex1 Ex1_2 Ex1x2 Ex1x3 Ex1x4 Ex1x5;Ex2 Ex2_2 Ex1x2 Ex1x3 Ex1x4 Ex1x5;...
Ex3 Ex3_2 Ex1x2 Ex1x3 Ex1x4 Ex1x5;Ex4 Ex4_2 Ex1x2 Ex1x3 Ex1x4 Ex1x5;Ex5 Ex5_2 Ex1x2 Ex1x3 Ex1x4 Ex1x5];
At = A';
G = [Ey1;Ex1_y1;Ex2_y1;Ex3_y1;Ex4_y1;Ex5_y1];
Ai = inv(At);
I want to make an inversion task but, I got the massage like this "Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN"
Is there any one can help me to slove my probelm?
ThxAkhmad Muktafhttps://it.mathworks.com/matlabcentral/profile/authors/7503568-akhmad-muktaftag:it.mathworks.com,2005:Question/4456752019-02-18T21:49:03Z2019-02-19T08:14:13ZHow to find Y value that corresponds to the maximum X value in these graphs?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.
Can anyone please help me with this?
Thank you.
Ismail Qeshtahttps://it.mathworks.com/matlabcentral/profile/authors/10292327-ismail-qeshtatag:it.mathworks.com,2005:Question/4457492019-02-19T08:09:57Z2019-02-19T08:09:57ZHow do I get the coordinates of a fit line using makedistI'm plotting a lognormal distribution where I use the command
[fit confidence] = lognfit(censoredFailTime,[],censored);
to fit a data set and then get the mean and standard deviation using
fitplot = makedist('lognormal','mu',fit(1),'sigma',fit(2));
To plot the data I'm using
plotprob = probplot('lognormal',censoredFailTime,censored,'noref');
probplot(gca,fitplot)
but I also want to extract the coordinates of the fit line as they appear on the graph. How can I get these coordinates from this?Janna Hinchliffhttps://it.mathworks.com/matlabcentral/profile/authors/14319116-janna-hinchlifftag:it.mathworks.com,2005:Question/189212011-10-20T20:42:43Z2019-02-19T08:09:44ZProblem with filtering an imageWhats up folks
I'm having a little problem in filtering this image:
http://img15.imageshack.us/img15/9287/palhaco.png
The source code is bellow:
C = imread('Palhaco.png');
imshow(C);
figure;
g = fspecial('gaussian',15,2);
imagesc(g); colormap(gray);
surfl(g)
figure;
gC = convn(C,g,'same');
imshow(convn(C,[-1 1],'same'));
figure;
imshow(convn(gC,[-1 1],'same'));
figure;
dx = convn(g,[-1 1],'same');
imshow(convn(C,dx,'same'));
figure;
lg = fspecial('log',15,2);
lC = convn(C,lg,'same');
imshow(lC)
figure
imshow(C + .2*lC)
When I compile the program, It returns:
"Integers can only be combined with integers of the same class, or scalar doubles."
I'm open to any idea at all!Rama Ratnahttps://it.mathworks.com/matlabcentral/profile/authors/3131038-rama-ratnatag:it.mathworks.com,2005:Question/4457482019-02-19T08:09:29Z2019-02-19T08:09:29Zwhat is the meaning of "wavelets localize features in data"Explain "wavelets localize features in data"ARCHANA PATILhttps://it.mathworks.com/matlabcentral/profile/authors/14418234-archana-patiltag:it.mathworks.com,2005:Question/4457472019-02-19T08:06:19Z2019-02-19T08:06:19ZWhat is the meaning of Wavelet coefficient which are small in value.Explain ,"wavelet coefficient which are small in value"ARCHANA PATILhttps://it.mathworks.com/matlabcentral/profile/authors/14418234-archana-patiltag:it.mathworks.com,2005:Question/4453082019-02-16T15:27:29Z2019-02-19T08:04:51ZSlider 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://it.mathworks.com/matlabcentral/profile/authors/14798685-hassan-boshatag:it.mathworks.com,2005:Question/4457452019-02-19T08:00:10Z2019-02-19T08:00:10Zwindow function on signal or vector hello
i want to do the window function , for example hamming window on a vector/Signal (1 row,654 column) , but not for whole length just from column 100th to 220th , but the problem is i dont know how to do that , my vector is given :
Man Ramhttps://it.mathworks.com/matlabcentral/profile/authors/14773820-man-ramtag:it.mathworks.com,2005:Question/4457442019-02-19T07:59:16Z2019-02-19T07:59:16ZWhat is meant by large-magnitude wavelet coefficient?Explain, meaning of large-magnitude wavelet coefficient.ARCHANA PATILhttps://it.mathworks.com/matlabcentral/profile/authors/14418234-archana-patiltag:it.mathworks.com,2005:Question/4457242019-02-19T06:00:03Z2019-02-19T07:54:04Zcreating a nested loop to change values within a for loopHi,
here is a code segment I am working on
n = 132 ;
M = cell(n,1);
for n = 1:132
for i = 1:132
for j = 1:49
if j~=2
[R P] = corrcoef(young_50(n,:,2),young_50(i,:,j))
r(j,i) = R(1,2);
p(j,i) = P(1,2);
end
end
end
M{n} = r;
M{n}(2,:) = []
end
what I need to do is change "if j~=2" to 3, 4,5...until 49, and also change young_50(n,:,2) similiarly. I then need to save M as M3, M4... to represent that particular output.
How can I go about doing that?Nativehttps://it.mathworks.com/matlabcentral/profile/authors/12921279-nativetag:it.mathworks.com,2005:Question/4457432019-02-19T07:49:48Z2019-02-19T07:49:48ZArduino to MATLAB GUI set upHello,
I am attempting to set up a GUI, which will establish an Arduino to MATLAB serial connection, retrieve the serial data and then output into "static text" boxes in the GUI. However, I am currently struggling to establish a serial connection within my GUI initialization code, through setting up the proper handles to be called out in my push buttons.
How may I set up the handles, as well as other parameters, such that the serial data will output into the static text boxes?
In the GUI intialization, this is my code:
function Feb10_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 Feb10 (see VARARGIN)
% Choose default command line output for Feb10
s = serial('/dev/tty.usbmodem14201');
fclose(s);
delete(instrfindall);
clear all
close all
clc
s = serial('/dev/tty.usbmodem14201','BaudRate',115200);
fopen(s);
handles.f = num2str(fscanf(s,'%f'));
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
And then in the latter function, which should call out the text box upon button press:
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)
m = 1;
t = 1;
f = handles.f;
while m == 1
plot([0 0],[0 50], [0 50], [50 0],[50 0], [0 0])
s_number(t) = sscanf(f(1), '%d');
s_value(t) = str2num(f(2:end));
handles.a = s_value(t);
textLabel = sprintf('Box 1 = %f', handles.a); % Will it let me do this or will I need to make a handle?
set(handles.text2, 'String', textLabel)
t = t + 1;
endNathan Banhhttps://it.mathworks.com/matlabcentral/profile/authors/7907106-nathan-banhtag:it.mathworks.com,2005:Question/4451772019-02-15T15:23:45Z2019-02-19T07:48:02ZError writing name_file.m. Access denied.Hi everyone, I have a sudden problem when I try to save or run the file. The error window say "Error writing name_file.m. Access denied". It's really strange because it has always worked well. I tryed to:
Change path location
Open Matlab as administrator
Change Matlab version from 2016 to 2018
Change Matlab file
But i have always the same problem. I can not understand what the problem could be. This is the screenshot:
michele paolettihttps://it.mathworks.com/matlabcentral/profile/authors/9117418-michele-paolettitag:it.mathworks.com,2005:Question/4455312019-02-18T09:08:02Z2019-02-19T07:42:33Zhelp 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://it.mathworks.com/matlabcentral/profile/authors/8027473-ahmed-s-sowayantag:it.mathworks.com,2005:Question/4457372019-02-19T07:22:22Z2019-02-19T07:41:38ZDouble click opens in current running Matlab instance on LinuxHello everyone,
Is it possible to have Matlab open its file types (.m, .mat ...) without using its GUI by double clicking just link on Windows?
If I try to do that a new matlab instance is launched. I do not find many people complaining about that, so I am guessing there is something wrong with my setup.Francesco Marronehttps://it.mathworks.com/matlabcentral/profile/authors/11941423-francesco-marronetag:it.mathworks.com,2005:Question/3848842018-02-26T13:15:45Z2019-02-19T07:40:33Z"CheckoutPolyspaceLicense, daemon answer" after installing Plug-in on EclipseHello,
I have installed Polyspace Plug-in for Eclipse along with Java-7.
After importing a project, I am trying to run Polyspace. For which I am getting below error :
*License Error
"Error in CheckoutPolyspaceLicense, Daemon answer"*
If needed, I am having licensed version of Polyspace installed on same machine.
What can be the issue ?? How to resolve it ??Vignesh BALACHANDARhttps://it.mathworks.com/matlabcentral/profile/authors/11722720-vignesh-balachandartag:it.mathworks.com,2005:Question/4457422019-02-19T07:40:32Z2019-02-19T07:40:32ZDraw acoustic modes of a roomHi, can anyone help to draw mode shapes (eigenmodes) of a room by usinf following equation.
P(x; y; z) = A*cos(pi*l*x/lx)*cos(pi*m*y/ly)-(m*pi/2)*cos(pi*n*z/lz)
Where lx, ly and lz are the width, length and depth of the room respectively.
l,m and n are the mode numbers of a room.HAFIS K Chttps://it.mathworks.com/matlabcentral/profile/authors/14821582-hafis-k-ctag:it.mathworks.com,2005:Question/4457412019-02-19T07:39:05Z2019-02-19T07:39:05ZError in using ePWM (TI F28027 LaunchPad) - Error evaluating 'InitFcn' callback of C280x/C2833x ePWM block (mask) 'untitled/ePWM'.I want to measure speed of motor, for that purpose I'm generating interrupt everytime motor makes one revolution. Now to calculate speed, I need to count how many pulses have been produced in specific time period. For this purpose I planned to use timer using ePWM and generating interrupt at every 1 sec. However it seems I cannot generate time dealys more than 1.something mSec (it gave me error). So for test purposes I tried generating pulse of 1mSec period, however I ran into following problem. Please help me in fixing this error. I'm using MATLAB2018a with TI C2000 F28027F LaunchPad which as base frequency of 60Mhz. Here's how error looks
For reference purposes, I'm also attaching screenshots of ePWM configuration if that helps (yeah right, I have no clue what I'm doing wrong, pls help me!)
Also, here's the snapshot of interrupt settings for ePWM1 interrupt.
Let me know if you need any more information, moderators may remove information which they think is unnecessary and will rather complicate things than being helpful to future visitors. Thanks in advance.Deephttps://it.mathworks.com/matlabcentral/profile/authors/11027372-deeptag:it.mathworks.com,2005:Question/4457362019-02-19T07:17:09Z2019-02-19T07:36:09ZPlot array data with its values only inside polygon I have a data 420*940*6 (the value of each grid varies from 0-100) and I want to plot data only inside polygon (s). lat (420*1) and lon1(940*1).
we can plot this signle page data in this way
S = shaperead(polygon);
N = length(S);
[X,Y] = meshgrid(lon1,lat1);
data= test;
for k = 1:N
idx = insidepoly(X(:),Y(:),S(k).X,S(k).Y);
hold on
plot(X(idx), Y(idx), 'r*')
end
How we can plot all pages (6) together according to values (0-100) as the attached figure?
Guide me in this regard.Shakir Hussainhttps://it.mathworks.com/matlabcentral/profile/authors/6413668-shakir-hussaintag:it.mathworks.com,2005:Question/4457392019-02-19T07:24:04Z2019-02-19T07:24:04ZHow should I write my code to do an image capture loop?for img = snapshot (cam) [1:10];
disp (image (img))
end
I'm trying to capture several images from matlab. My code restricts to only ten captures. On running the code, a lot of info like this is displayed,
Use get to show all properties
Image with properties:
CData: [480x1 uint8]
CDataMapping: 'direct'
Please assist me find a suitable code to capture several matlab images from webcam. Used support package, USB Webcams.Daniel Obarehttps://it.mathworks.com/matlabcentral/profile/authors/13908287-daniel-obaretag:it.mathworks.com,2005:Question/4457382019-02-19T07:22:57Z2019-02-19T07:22:57ZRunning WebApp server in silent modeHi!
I am currently setting up Matlab WebApp server on a CentOS7 server. Everything runs well. The WebApp server is running and I can deploy apps and access them from other desktop machines in the LAN.
But now I want to integrate the WebApp server in systemd service. For this I need to be able to start the WebApp server in silent mode with no GUI. Is this somehow possible? Or are there other possibilities?
Currently I have to be logged-in the server to keep the WebApp service running.
Best Regards,
UdoUdo Schröderhttps://it.mathworks.com/matlabcentral/profile/authors/6580945-udo-schrodertag:it.mathworks.com,2005:Question/4457262019-02-19T06:15:31Z2019-02-19T07:08:26ZVector as Function InputI want to find a way to pass the inputs to a function as a vector instead of having to specify the individual inputs to the function. I want to do this because I have another function that takes in a function handle as its input as well the input values to that function to generate a set of sigma points(I'm writing a ukf). It looks a bit like this(very over-simplified
function [x]=myFunc(func_handle,func_input)
x = func_handle(func_input)
end
Now the issue is in my implementation of the func_handle, if I declare a function as follows, I have no issues.
test_func = @(x)[x(1) + x(2); x(2)^2; x(1)^2 + x(3)^2];
But for my application, my function is very long and complex and can't be written in a single line as such so I have it written in terms of symbolic expressions. But when written as such, I can't get it to work right. I could use some help with being able to define the function such that the input values can be given as a vector so it can be used in the above function properly.
%% Function Test
clear all
close all
syms a b c
test1 = b+a;
test2 = b^2;
test3 = a^2 + c^2;
test = [test1;test2;test3];
test_func = @(input)[test1;test2;test3];
test_input = [1;2;3];
test_func(test_input) %This doesn't work
test_func = matlabFunction(test);
test_func(test_input(1),test_input(2),test_input(3)) %This works but input can only be one sizeCory Ibanezhttps://it.mathworks.com/matlabcentral/profile/authors/3077557-cory-ibaneztag:it.mathworks.com,2005:Question/4452742019-02-16T08:58:13Z2019-02-19T07:07:22ZFFT from CSV fileI'm trying to perform FFT on the 2nd data column of a .csv file. The .csv file is quite large and the zipped version can be found here: https://www.dropbox.com/s/87l5vtxdqfbtt6x/Tridral_1m_1ms.7z?dl=0
The signal is 10 milliseconds long, and is sampled 1 million times over that time period. I've tried following the FFT example provided by the help file, but the frequency domain signal does not come out right. The FFT output gives a strong DC signal (that could be right), and a signal at 50 KHz. Based on the time domain signal, i should expect approximately a 1 KHz fundamental with recurrent harmonics at 2, 3, 4 KHz..., but it comes out empty... am i doing something wrong in my code?
Ray Fanghttps://it.mathworks.com/matlabcentral/profile/authors/14791516-ray-fangtag:it.mathworks.com,2005:Question/2324382015-08-05T08:36:47Z2019-02-19T06:58:15ZRead data in log.lammps from LAMMPS to MatlabI simulate by LAMMPS and have a log.lammps file. Now I want to use data from this file to Matlab.
How can I read data to Matlab? The log.lammps (change to .txt) file is attached.lyhttps://it.mathworks.com/matlabcentral/profile/authors/6006563-lytag:it.mathworks.com,2005:Question/4443502019-02-11T15:11:19Z2019-02-19T06:57:51ZColormap on polarhistogram barsHi,
Is there any way to include a colormap on the polarhistogram bars? For example, based on the code below
close all;
clear all;
clc;
% Random theta values between 0 and 2*pi
a = 0;
b = 2*pi;
theta = (b-a).*rand(1000,1) + a;
% Random values between -100 and 100
c = -100;
d = 100;
val = (d-c).*rand(1000,1) + c;
data = [theta val];
% Plotting
f1 = figure(1);
p(1) = polarhistogram(data(:,1),...
'BinEdges',[deg2rad(0):deg2rad(15):deg2rad(360)],...
'Normalization','probability','FaceAlpha',1);
ax = gca;
ax.ThetaZeroLocation = 'top';
ax.ThetaDir = 'clockwise';
The polarhistogram is generaetd based on the values of the data(:,1) column. It would be useful to have a colormap based on the corresponding values of data(:,2).
MichailMhttps://it.mathworks.com/matlabcentral/profile/authors/9848527-michailmtag:it.mathworks.com,2005:Question/3633882017-10-26T12:40:08Z2019-02-19T06:55:00ZMigrating from Matlab 2015b to 2017b errorI have a model that can be run in Matlab 2015b & 2013b, but when I try to run in 2017b, I get the following error.
MATLAB Function uses constructs that are invalid when the block specifies or inherits a continuous sample time. Invalid constructs include the use of persistent or global variables, calls to exported functions or using coder.extrinstic.
Suggested Actions
Set sample rate of this block to inherit the fastest discrete rate in the model.
Fix
Open the properties dialog of this block to set the sample time manually.Sohrab Safavihttps://it.mathworks.com/matlabcentral/profile/authors/2236596-sohrab-safavitag:it.mathworks.com,2005:Question/4450422019-02-14T20:04:37Z2019-02-19T06:54:30ZMatlab not download completlyHello,
My matlab will get from 10-18% and then will stop downloading. I have tried different versions of downloading. Also, I have tried restarting and erasing data so there is a blank slate but nothing is working. I have downloaded mac before but my lisence is up and have to re download it from my universitys data base. amber clarkhttps://it.mathworks.com/matlabcentral/profile/authors/8615449-amber-clarktag:it.mathworks.com,2005:Question/4456962019-02-19T00:49:15Z2019-02-19T06:51:25ZWant to share my codehi, I want to share my matlab code that I use for my web-based project thesis. I got a lot of help completing the MATLAB program code from this forum, but I want to share it again. My code is complete with manual calculations that I take from several theories and manual network calculations such as multilayer perceptron.
Because maybe I will not continue concentrating on the image processing, rather than not being used and I think someone wants to continue, so it is good. This is not perfect, but if someone experiences problems like me, my it can help little. Can I share it here? because the size is quite large including php code. Thank youOman Wisnihttps://it.mathworks.com/matlabcentral/profile/authors/13491522-oman-wisnitag:it.mathworks.com,2005:Question/4457282019-02-19T06:24:08Z2019-02-19T06:46:45ZProgramme is not giving any outputfor i=1:size(X,1)
t1=abs(centroids(1,1)-X(i,1));
t2=abs(centroids(2,1)-X(i,1));
T(i,:)=[t1 t2];
MINM(i,1)=min(T(i,:));
if MINM(i,1)==T(i,1)
Sample(i,1)=1;
else
Sample(i,1)=2;
end
end
Location=find(Sample==1);
this programme is not giving any output and even errors also.. up to 1hr also it is not giving any output.
Kindly help me to resolve this.shashikala chavanhttps://it.mathworks.com/matlabcentral/profile/authors/8396884-shashikala-chavantag:it.mathworks.com,2005:Question/4457332019-02-19T06:46:07Z2019-02-19T06:46:07Z Help me, I want to take the values from Arduino to the graph. Serial Monitor values of ARDUINO are x, y, z
Help me, I want to take the values from Arduino to the graph. Serial Monitor values of ARDUINO are x, y, zjassada promthonghttps://it.mathworks.com/matlabcentral/profile/authors/14790620-jassada-promthongtag:it.mathworks.com,2005:Question/4453422019-02-16T21:13:43Z2019-02-19T06:45:31ZHow to properly run simple Simulink circuit?Good day,
I am having issues with simulink. I am trying to simulate a portion of a circuit that I am trying to develop. I am just not understanding how simulink works. I created a portion of my circuit, stepping up a 12V DC voltage from a battery (from a DC to DC converter) to 4.5kv and it's suppose to charge a capacitor.
Source is 12 V - stepping it up to 4.5kV, and the capacitor should be charged at 4.5kV of course. I put a volt meter or a "voltage sensor" in parallel with the capacitor to verify the voltage.
The potentionmeter is used to adjust the DC-to-DC converter output (output should be somewhat linear to input). In real life, I have a dc-to-dc converter that has a max output of 6000V, and 1.67mA. At max, it draws a maximum of 1.5A. The dc-to-dc converter that I have is a 12V source.
I have attached the file, I hope someone can help me. This is driving me nuts.
When I am trying to run it, I am getting the following error.
I am using simscape for this. If there is a better recommendation please let me know.
Thank you in advance!!!
The model may not give enough information to make it possible to solve for values of some of its variables. Specific advice is given below.
Tie variable 'Voltage_Sensor.p.v' (Voltage) to a definite value, for example by connecting an appropriate domain reference block.
Dependency found among topology equations. Check for missing reference node.
Component:Simulink | Category:Modelwarning
The model may not give enough information to make it possible to solve for values of some of its variables. Specific advice is given below.
Tie variable 'Voltage_Sensor.p.v' (Voltage) to a definite value, for example by connecting an appropriate domain reference block.
Dependency found among topology equations. Check for missing reference node.
Component:Simulink | Category:Modelwarning
An error occurred while running the simulation and the simulation was terminated
Caused by:
At time 0.000000, an assertion is triggered. Supply-side current exceeded the Maximum expected supply-side current. The assertion comes from:
Block path: step_up_charge_cap/DC-DC Converter
Assert location: (location information is protected)
Component:Simulink | Category:Blockerrorcancel077https://it.mathworks.com/matlabcentral/profile/authors/2013163-cancel077