https://it.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-12-15T18:13:52Ztag:it.mathworks.com,2005:Question/4358942018-12-15T13:53:36Z2018-12-15T18:13:52ZFourier transform how to get coefficientsHey everyone, i know that matlab have the method for fourier transform implemented but i was wondering if there is anything that could give me coefficients of fourier transfrom.Vincent Sinhttps://it.mathworks.com/matlabcentral/profile/authors/13709665-vincent-sintag:it.mathworks.com,2005:Question/4353022018-12-12T08:28:26Z2018-12-15T18:13:43ZProblem with solve functionHi if I use the solve function it doesnt work, like on my colleagues computer.
Here an example:
>> syms x
>> d=solve(x*5+15,x)
d =
-3
>> d=solve(x*5+15==0,x)
d =
x
somehow I get d=-3 when I let the ==0 out, but this makes no sense to me.
Even when I use the example from the help Page
syms x
eqn = sin(x) == 1;
solx = solve(eqn,x)
my result is solx=x
Has anyone an Idea, what I am doing wrong? Maybe some settings I need to change?
Thank you for your help
Dorian Jaggihttps://it.mathworks.com/matlabcentral/profile/authors/13542294-dorian-jaggitag:it.mathworks.com,2005:Question/4358302018-12-14T20:32:13Z2018-12-15T18:13:05ZHow does one store all the words from a loop into a variable?
words1 = readTextFile('abc.txt');
words2 = readTextFile('def.txt');
% Access the text file and write contents into an array
wordsA = [words1; words2];
%combining words from both arrays
words3 = readTextFile('ghi.txt');
words4 = readTextFile('jkl.txt');
% Access the text file and write contents into an array
wordsB = [words3; words4];
%combining words from both arrays
Shuffle1 = randperm (length(wordsA));
Shuffle2 = randperm (length(wordsB));
% Create a random array of numbers for the file to be matched to
for i = 1:length(wordsA)
PositionA = Shuffle1 (i); % Use number from the random array
% wordsA (PositionA); % Assign random position to words in text file
RandomWordsA = wordsA(PositionA); %Assign the obtained list to a varible to be displayed
disp (RandomWordsA) %display the random word list
end
for j = 1:length(wordsB)
PositionB = Shuffle2 (j); % Use number from the random array
% wordsB (PositionB); % Assign random position to words in text file
RandomWordsB = wordsB(PositionB);
% RandomWordsB = wordsB(PositionB); %Assign the obtained list to a varible to be displayed
disp (RandomWordsB) %display the random word list
end
RandomWords = [RandomWordsA; RandomWordsB]; %combining words from both arrays
disp (RandomWords) %display the random word lists
Lvny Mhnhttps://it.mathworks.com/matlabcentral/profile/authors/14369521-lvny-mhntag:it.mathworks.com,2005:Question/4359152018-12-15T17:26:32Z2018-12-15T18:12:12Zwhy is not possible to do the logic also why not displayHi
I dont know why I cant display my logick code also an error message on it as well
>> u=symunit;
L= input('Lenght of the wind turbine blade in meter: ')*u.m;
L=unitConvert(L,u.mm);
W=8500*u.N;
E=42000 *u.N/u.mm^2;
I=10*(10^6)*u.mm^4;
D=vpa((W*L^3)/(8*E*I));
Limit= L*0.1;
if D<=Limit disp('Maximum deflexion is tolerable')
else disp('Maximum deflexion will be exceeded')
end
Lenght of the wind turbine blade in meter: 10
Conversion to logical from sym is not possible. Milan Sumegihttps://it.mathworks.com/matlabcentral/profile/authors/13607472-milan-sumegitag:it.mathworks.com,2005:Question/4359202018-12-15T18:09:01Z2018-12-15T18:09:01ZDesign filter to remove two different frequenciesI have to design a filter to remove the noise that has been added to an audio signal with fs=44100.
The noise exists in only two frequencies and the filter should remove them.
Which type of filter is able to do this?
Maha Alshttps://it.mathworks.com/matlabcentral/profile/authors/13785315-maha-alstag:it.mathworks.com,2005:Question/4116582018-07-23T08:59:18Z2018-12-15T18:07:28ZHow to plot just a colorbar without plot?I would like to plot just a colorbar on a subplot without real figure. I can do this, but I want to shrink the figure area. How to make zero figure width and wide colorbar?Mr M.https://it.mathworks.com/matlabcentral/profile/authors/4980938-mr-mtag:it.mathworks.com,2005:Question/4358672018-12-15T08:14:52Z2018-12-15T17:59:00ZHow to (efficiently) replace eval() with subs() for symbolic equationsHi,
I've been trying to convert a code I have for modeling a curve into a Simulink model (so, eventually, I'll be able to run automatic parameter estimation). The code itself is comprised of a few different symbolic functions. I previously used the code in Matlab 2012b (where it exectutes very quickly without problems) however I couldn't make it work in Simulink because of the C++ compiler issue. I tried to apply the patches to resolve the compiler problem with no sucess so I gave up and switced over to 2018b. Now the problem seems to be trying to replace the eval() function which is no longer supported. My best solution to date uses sub() and str2sym(). This works but is so slow that it's effectively useless. Does anybody have suggestions on how I can improve the code?
Old version:
for kt=1:nnt
tt=radt(kt); s=alfa/tt; bt=beta/tt; btF=bt.*eval(FF); ft(kt)=sum(real(btF));
end
New version:
btf=@(s,bt) double(bt.*subs(str2sym(Fs)));
for kt=1:nnt
tt=radt(kt); s=alfa/tt; bt=beta/tt; btF=btf(s,bt); ft(kt)=sum(real(btF));
end
For reference, a simplified version of FF is: '(0.1*s)^(1/2)*besselk(0.0, 8.0*(0.1*s)^(1/2))'
I'll include the files being used in case anyone would like to take a look in more detail.
Thanks in advance for any assistance!Nat Ahttps://it.mathworks.com/matlabcentral/profile/authors/13679374-nat-atag:it.mathworks.com,2005:Question/4359112018-12-15T16:59:43Z2018-12-15T17:56:06ZConvert each row of a grayscale image from decimal to binary and store it in an arrayI have the following code which pops up an error 'Unable to perform assignment because the indices on the left side are not compatible with the size of the right
side.' along with 'Error in input_image (line 13) in_signal(1,(((i-1)*n*8)+1):(i*n*8)) = in_img_bin;'
clc;
close all;
%256 x 256 image in grayscale
in_img = imread('image.bmp');
%image to binary code
in_signal= [];
n=256; %image size
for i= 1:n
%convert each row of image from decimal to binary
[in_img_bin] = dec2bin(double(in_img(i,:)));
%save into rows of size equal of 2048 elements => 256*8
%e.g.,1-2048, 2049-4096, ...
in_signal(1,(((i-1)*n*8)+1):(i*n*8)) = in_img_bin;
end
%output->in_signal
%____________________________________________________
out_signal = in_signal;
% binary code -> image %
% input-> out_signal
out_img =uint8(zeros(n,n));
[out_img_d] = bin2dec(out_signal);
out_img = uint8(out_img_d);
figure(1)
imshow(in_img)
figure(2)
imshow(out_img)
%__________________________________________________________________________
Dhanya Mallagundahttps://it.mathworks.com/matlabcentral/profile/authors/14368542-dhanya-mallagundatag:it.mathworks.com,2005:Question/4359192018-12-15T17:55:32Z2018-12-15T17:55:32ZHow to detect the edges in the picture using Robert, Sobel and Prewitt's operator?Hi, I'm pretty new to Matlab and I need help in the task. It is necessary to apply Robert's, Sobel's and Prewitt's edge detectors to a picture, then interruptions in the contour edges fill and connect the contour.
Any help would be greatly appreciated.
Thank youMiralem Ikanovichttps://it.mathworks.com/matlabcentral/profile/authors/7497405-miralem-ikanovictag:it.mathworks.com,2005:Question/4359182018-12-15T17:53:59Z2018-12-15T17:53:59Zhow to upload csv file and save its all values using guide (GUI)Hİ,
I am currently making GUI in matlab I am new to it. actually through GUI I want to select a .csv file and I want upload all element in that GUI to a variable. I am successfully selecting the file but unable to read its value.
this is my code:
% --- Executes on button press in pushbutton1.
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)
[filename pathname] = uigetfile({'*.csv','file selector'});
fullpathname = strcat (pathname, filename);
text = csvread(fullpathname);
set(handles.text2,'string',fullpathname)
I want this when I browse my file from the folder I can select csv file and then when I press upload button it will save its all values in a variable.Muhammad Haziqhttps://it.mathworks.com/matlabcentral/profile/authors/11787906-muhammad-haziqtag:it.mathworks.com,2005:Question/4359172018-12-15T17:53:25Z2018-12-15T17:53:25Zgive constant parameters to fitnlmI want to use fitnlm (rather than fminsearch and a cost function) because it has the built in statistics. I need to run the fit of the model with different costant parameters but I am not able to tell the function to pick a parameter from the workspace (the function return an error if I give three arguments like @(parameterToOptimise,xData,constantParameter).
My example is:
fit function and the values to fit are and I have a constraint on the area under the curve that is A (depending on the fit problem).
I would like to write
@(,x,Area)[(+1)*Area/(-)*] (luckly and are constant, so I can write the numerical values), but I am not able to give a constant parameter to the function
FastCarhttps://it.mathworks.com/matlabcentral/profile/authors/8926157-fastcartag:it.mathworks.com,2005:Question/4355432018-12-13T11:23:29Z2018-12-15T17:51:54ZHow to interpret statistics from glmfitI did a logistic regression for binomial data and the stats obtained are attached with this. I am getting avery hard time to understand the statisitics. Why there are two p-values and what does it signify?
Hari krishnanhttps://it.mathworks.com/matlabcentral/profile/authors/13142902-hari-krishnantag:it.mathworks.com,2005:Question/4358452018-12-14T22:14:05Z2018-12-15T17:48:24ZHow can I use pushbuttons in GUI to categorize a "like" or "dislike" of a imageI've been stuck on this problem and can't seem to find the right kind of tutorials online that would point me in the right direction.
My goal is to use a GUI that has two pushbuttons, a "like" and a "dislike" pushbutton.
I add the folder with all the images to my path so when my gui opens, the first image automatically pops up. Then I hit "like" or "dislike", and that information is saved as a logical corresponding to the image title in a structural array.
I've spent several hours working on creating practice GUI's that do other things to understand how everything works together, but I'm feeling in over my head maybe? Does anyone have any idea's, hints, or resources that they have in mind? Rachel Larsenhttps://it.mathworks.com/matlabcentral/profile/authors/13575761-rachel-larsentag:it.mathworks.com,2005:Question/4357572018-12-14T13:03:37Z2018-12-15T17:43:12ZHow to get environment password in script/functionI know it is possible to extract environmental parameters like the username like this
getenv('username')
but is it also possible to extract the password?Johnny Birchhttps://it.mathworks.com/matlabcentral/profile/authors/13117929-johnny-birchtag:it.mathworks.com,2005:Question/1843712015-03-21T17:59:12Z2018-12-15T17:40:57ZSolving a system of 4 linear equations with Gauss MethodI have written a basic code to help solve this problem, but Matlab is giving me an error.
%Gauss Method
clear;clc;format('long','g')
i=1;
x(i)=1;
y(i)=1;
z(i)=1;
t(i)=1;
errorx(i)=9999;
errory(i)=9999;
errorz(i)=9999;
errort(i)=9999;
while errorx(i)>=10^-5 || errory(i)>=10^-5 || errorz(i)>=10^-5 ||errort(i)>=10^-5
x(i+1) = (2 - y(i) + z(i) - 2*t(i))/5;
y(i+1) = (1 + z(i) + x(i) - t(i))/4;
z(i+1) = (3 - x(i) - y(i) - t(i))/5;
t(i+1) = (4 +2*x(i) - y(i) +2*z(i))/8;
errorx(i) = abs((x(i+1)-x(i))/x(i));
errory(i) = abs((y(i+1)-y(i))/y(i));
errorz(i) = abs((z(i+1)-z(i))/z(i));
errort(i) = abs((t(i+1)-t(i))/t(i));
i=i+1;
end
disp([x',y',z',t'])
and the error is
??? Attempted to access errorx(2); index out of bounds because
numel(errorx)=1.
Error in ==> gaussmethodas3 at 12
while errorx(i)>=10^-5 || errory(i)>=10^-5 || errorz(i)>=10^-5
||errort(i)>=10^-5Robert Ungerhttps://it.mathworks.com/matlabcentral/profile/authors/2587601-robert-ungertag:it.mathworks.com,2005:Question/4359162018-12-15T17:39:59Z2018-12-15T17:39:59ZPiecewise integration - implied volatilityHi,
I'm trying to integrate a piecewise function and I'm having slight troubles. The function is as below:
Now I have a column vector for the differing C and S values. However I'm having trouble with the max condition and the differing Ks.
The 5200 and 11150 is the range that I'm specifying as strike prices dont range into the infinity.
Below is my attempt....Would be great if someone could help me out.
I get the error: "Index in position 1 exceeds array bounds (must not exceed 1)".
I've had attempts with varying code and I have not been successful.
fun = piecewise(S-K>0,((C-(S-K))./K^2),S-K<0,((C-0)./K^2));
q = zeros(length(SortedDax),1);
for i = 1:length(SortedDax)
q(i,1) = 2.*integral((@(K)fun(SortedDax(i,4),SortedDax(i,30),K)),5200,11150);
endHyunsin Kimhttps://it.mathworks.com/matlabcentral/profile/authors/12727745-hyunsin-kimtag:it.mathworks.com,2005:Question/4359122018-12-15T17:01:44Z2018-12-15T17:38:19ZError Message: expression or statement is incorrectI'm trying to create a code for least squares curve fitting, but when I make the function handle to be evaluated in the command window, I keep getting this error message saying that the the expression is incorrect. Below is the code I've made along with the inputs in the command window:
command window:
Running Least Squares Method...
X-Values: [0 10 20 30 40 50 60 70 80 90 100 110]
Y-Values: [3589 4132 6307 7814 11842 18072 27542 33141 44337 55002 65660 76201]
Function: (@K, r, timedat) ((popdat(1) * K ) / (popdat(1) + (K - popdat(1)*exp(-r * timedat))))
Error using LeastSqMethod (line 13)
Error: Expression or statement is incorrect--possibly unbalanced (,
{, or [.
Code:
clear
clc
%% Step 1 - Inputting Data
disp('Running Least Squares Method...');
disp(' ');
timedat = input('X-Values: '); % Array of X Values (Time)
popdat = input('Y-Values: '); % Array of F(x) Values (Population)
func = input('Function: '); % Function to be evaluated
x0 = input('Initial Guess: ');
%% Step 2 - Least Squares Fit Determination
fit = lsqcurvefit(func, x0, timedat, popdat)
%% Step 3 - Plotting Results
xrange = input('Enter X-Value Range: ');
plot(timedat,popdat,'ko',xrange,func(fit,xrange),'b-')
legend('Given Data', 'Model Fit')
xlabel('Time (Years)')
ylabel('Population')
title('Population Growth in Bryan, TX')
grid onChristopherhttps://it.mathworks.com/matlabcentral/profile/authors/2116124-christophertag:it.mathworks.com,2005:Question/4359142018-12-15T17:07:34Z2018-12-15T17:38:11Zdelete row by clicking UITABLEHi everybody,
once the row of the table has been selected with the mouse I would like to delete it with the delet row button.
When I push delet button I can't select the Indices. Matlab shows me the following answer:
Index =
1×0 empty double row vector
Struct contents reference from a non-struct array object.
The following code:
function varargout = tabella(varargin)
% TABELLA MATLAB code for tabella.fig
% TABELLA, by itself, creates a new TABELLA or raises the existing
% singleton*.
%
% H = TABELLA returns the handle to a new TABELLA or the handle to
% the existing singleton*.
%
% TABELLA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TABELLA.M with the given input arguments.
%
% TABELLA('Property','Value',...) creates a new TABELLA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before tabella_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to tabella_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help tabella
% Last Modified by GUIDE v2.5 15-Dec-2018 17:52:27
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @tabella_OpeningFcn, ...
'gui_OutputFcn', @tabella_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before tabella is made visible.
function tabella_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 tabella (see VARARGIN)
% Choose default command line output for tabella
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes tabella wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = tabella_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in add_row.
function add_row_Callback(hObject, eventdata, handles)
% hObject handle to add_row (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=get(handles.uitable4, 'data');
data(end+1,:)={''};
set(handles.uitable4, 'data', data);
% --- Executes on button press in delete_row.
function delete_row_Callback(hObject, eventdata, handles)
% hObject handle to delete_row (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.uitable4,'CellSelectionCallBack',@(h,e) set(h,'UserData',e))
D=get(handles.uitable4,'Data');
Index=get(handles.uitable4,'UserData')
D(Index.Indices(:,1), :) = [];
set(handles.uitable4,'Data',D);
dario cecchettihttps://it.mathworks.com/matlabcentral/profile/authors/9844697-dario-cecchettitag:it.mathworks.com,2005:Question/4359032018-12-15T15:32:01Z2018-12-15T17:37:24ZLinearizing of electrimechanical system Simulink Model. How to do it ? Hi there,
I have electromechanical system Simulink model, with the following components:
1-The mechanical subsystem equations represented by basic operators
2- The controller contains a look-up table, PID controllers and SVPWM.
3- PM synch. motor.
I am facing a problem of getting zero reference values because the PID controller doesn't linearize the system.
My background about linearization is really very basic, especially in Simulink environment! bucause of that, I couldn't fix the issue. What do you think the problem is? Is it in PID linearization? or any other setting in Simulink? I really need a guiding recommendation.
RegardsAli Bashabshehhttps://it.mathworks.com/matlabcentral/profile/authors/11554322-ali-bashabshehtag:it.mathworks.com,2005:Question/4259172018-10-24T04:00:00Z2018-12-15T17:36:45ZHow to install and launch Simulink Onramp?I found Simulink Onramp in the Getting Started list of my MATLAB Courses
<https://matlabacademy.mathworks.com/>
and on MATLAB Central:
<https://www.mathworks.com/matlabcentral/fileexchange/69056-simulink-onramp>
How can I install and and launch Simulink Onramp?
MathWorks Support Teamhttps://it.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:it.mathworks.com,2005:Question/4359132018-12-15T17:04:55Z2018-12-15T17:33:57ZPlease how can I plot the graph of the function it keep giving me Error in QCS2 (line 13), ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin); %%System Parameters
M = [400 0;0 40];
C= [12000 -12000;-12000 12125];
K = [80000 -80000;-80000 280000];
B = [0 0;200000 125];
[t,y] = ode45(@(t,y) MSsys(t,y,M,K,C,B),[0 20],[0 0 0 0])
x1 = y(:,1); x2 = y(:,2);
plot(t,x1,t,x2)
xlabel('Time (seconds)')
ylabel('x_1(t)and x_2(t) (m/sec)')
title('Speed Bump')
%%ODEs
function dydt= MSsys(t,y,M,K,C,B)
A = [zeros(2) eye(2);-inv(M)*K -inv(M)*C];
F = [0 0;200000 125]*0.03*sin(50*t);
dydt = A*y+[zeros(2);inv(M)*B]*F;
endSimisolaoluwa Adekoyahttps://it.mathworks.com/matlabcentral/profile/authors/13524724-simisolaoluwa-adekoyatag:it.mathworks.com,2005:Question/4359082018-12-15T16:34:03Z2018-12-15T17:31:42ZHow can I import only the numbers from an csv.-files with a text header?I have hundreds of .csv-files, I attached one of them for example (Had to shorten it, beacuse it was bigger than 5 MB). Each of them has 10^6 Lines with data.
And I want to import those files automatically in my Matlab code. It is totally enough to import them one by one, but unfortunately I always had to preprocess this data manually with Text Editor. The problem is the text in the header of every .csv-file. I just want to import the numbers of the second, third and fourth column and not the text from the header. But even if I specify the columns, I cannot convert the recieved data store in numbers to run the calculations. This is my solution with the preprocessed data:
pre_data = datastore('Bermuda-Azoren_0012018-03-07 19.38.47.018_A0003.csv');
piece = zeros(1,3);
while hasdata(pre_data)
pie = read(pre_data);
pie = pie(:,1:3);
pie = table2array(pie);
piece = [piece; pie];
end
piece = piece(9:10^6+8,:);
With "piece", I can now easily run the calculations
To import the data without preprocessing, I tried "ds.SelectedVariableNames" and replacing "datastore" with "csvread". But nothing works.
Have anyone an advice, how to import such csv-files as an easily processable 1000000x3-double?Christoph Müßighttps://it.mathworks.com/matlabcentral/profile/authors/13142736-christoph-mussigtag:it.mathworks.com,2005:Question/4358652018-12-15T07:29:16Z2018-12-15T17:31:02ZHow I can plot a vehicle's velocity at different points on a mapI am working on driverless car. I have rosbag data. Now I have to plot imu and Gps data on a given map. How can I do that. Such that at every point on map I have knowledge of at what point what was yaw angle, what was velocity, acceleration etc.Ichchhit Kumarhttps://it.mathworks.com/matlabcentral/profile/authors/13917399-ichchhit-kumartag:it.mathworks.com,2005:Question/4356322018-12-13T19:44:48Z2018-12-15T17:20:04ZProblems with plotting multiple objects
Hi! I have a question. There are the label of contour on the rectangle. Can I delete this for a better reading? Thank you
This is the code for the graphic part.
[c,cc]=contour(x,y,u',[13.1,13.5,14,14.5,15,15.5,15.9]);
clabel(c,cc,'LabelSpacing',72,'Color','r','FontWeight','normal');
rectangle('position',[0,0,Lx,Ly])
rectangle('position',[x(6),y(4),d,3*d],'FaceColor',[0.5 0.5 0.5],'LineWidth',1)
axis('equal');
set(cc,'ShowText','on');
colormap cool;
axis([0 Lx 0 Ly]);
hold on;
streamline(x,y,qx,qy,[x(2:4),x(9:nx)], y(ny+1)*ones(1,6));
quiver(x(2:5),y(2:ny),qx(2:ny,2:5),qy(2:ny,2:5),'b');
quiver(x(8:nx),y(2:ny),qx(2:ny,8:nx),qy(2:ny,8:nx),'b');
quiver(x(6:7),y(2:3),qx(2:3,6:7),qy(2:3,6:7),'b');
trimesh(T,P(:,1),P(:,2),hh);
title('Sheet pile wall');
xlabel('x');ylabel('y');zlabel('z');MICHELA VOLGAREhttps://it.mathworks.com/matlabcentral/profile/authors/13760896-michela-volgaretag:it.mathworks.com,2005:Question/4358902018-12-15T13:31:55Z2018-12-15T17:18:05ZHow to build the stress strain curve from displacement?I am very much new in matlab, how to find the stress strain curve from displacement? i have the big data from Digital Image Correlation (DIC) software.
please give some idea how to start. thanks in advance.humayun kabir biplobhttps://it.mathworks.com/matlabcentral/profile/authors/14354720-humayun-kabir-biplobtag:it.mathworks.com,2005:Question/4359042018-12-15T15:55:52Z2018-12-15T17:13:57Zhow to use fft to find my motor acceleration's frequencyhi, I'm new in using matlab, i was tried to find my motor's frequency by using fft, but i got in trouble, i tried lot of examples on the internet but it didn't work, if somebody can give my some tips i will be so appreciate!!!
my sampling rate is about 8hz, and in txt is the acceleration of motor about 1024,and this code is one of example i copy from internet,even it doesn't works.
c=textread('C:\Users\wkj88\Desktop\11.txt', '%f') ;
T=1/250;
L=length(c);
Fs=1/T;
t=(0:L-1)*T;
Y = fft(c);
mag1 = abs(Y/L);
mag = mag1(1:L/2+1);
mag(2:end-1) = 2*mag(2:end-1);
ph1 = rad2deg(Y/L);
ph = ph1(1:L/2+1);
ph(2:end-1) = 2*ph(2:end-1);
f=Fs*(0:(L/2))/L;
subplot(2,2,[1,2])
plot(t,c);
title('Vibration Signal');
xlabel('Time (seconds)');
ylabel('Amplitude (voltage)');
subplot(2,2,3)
plot(f,mag);
title('Magnituge Plot');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
subplot(2,2,4)
plot(f,ph);
title('Phase Plot');
xlabel('Frequency (Hz)');
ylabel('Phase (degree)');louis wanghttps://it.mathworks.com/matlabcentral/profile/authors/13120361-louis-wangtag:it.mathworks.com,2005:Question/4357982018-12-14T17:07:48Z2018-12-15T17:07:11ZWindowing and extracting data from a plot by selecting a zoneHello Everyone,
Motive behind this question is it possible to have a movable window in a figure Where the user moves the window and acquires the desired range of data from a figure?
2) I have tried ginput (by defining 2 points) it does acquire the range of data selected by the user, but the issue in my case is i do not know how many cycles of data is acquired everytime. So would not know how many times do i have to loop ginput for the user to select new range of data everytime.
3)In the Code you would find Variable "Angle" which i haven't used anywhere reason being I want to plot Torque agnist a random x-axis. Select my zone/range have that selected range of torque data compared orginal Torque Data (To know the size of the extracted file) angle data here has the same size as Torque so Now the selected range of torque and its corresponding "Angle" could be written out into a excel file making in (nx2) Matrix.
Any Help would be appreciated. Also copying my code below and have attached a picture which explain what windowing i am talking about.
[filename,pathname] = uigetfile('*.xlsx');
fullfilename = fullfile(pathname,filename);
A = xlsread(fullfilename);
Torque = movmean(A(:,1 ),50);
Angle = movmean(A(:,2),50);
h = plot(Torque);
saveas(h,'All_Data.fig');
% hold on
%pts = ginput(2) ;
h = hgload('All_Data.fig');
get(h)
ch = get(h,'Children');
l = get(ch,'Children');
y = get(l,'ydata')
Anand Gudlurhttps://it.mathworks.com/matlabcentral/profile/authors/8678603-anand-gudlurtag:it.mathworks.com,2005:Question/4358972018-12-15T14:18:48Z2018-12-15T16:58:43ZDimensions of arrays being concatenated are not consistent error.How to fix this error?
Error using HelperTestKNNClassifier (line 35)
Could not concatenate the table variable 'ActualSpeaker' using VERTCAT.
Caused by:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
for idx = 1:length(Filenames)
T = featuresTest(Fidx==idx,2:end); % Rows that correspond to one file
predictedLabels = string(predict(trainedClassifier,T(:,1:15))); % Predict
totalVals = size(predictedLabels,1);
[predictedLabel, freq] = mode(categorical(predictedLabels)); % Find most frequently predicted label
match = freq/totalVals*100;
result_file.Filename = Filenames(idx);
result_file.ActualSpeaker = T.Label{1};
result_file.PredictedSpeaker = char(predictedLabel);
result_file.ConfidencePercentage = match;
result = [result; struct2table(result_file)]; %#ok
endLeonidas Daedalushttps://it.mathworks.com/matlabcentral/profile/authors/14282267-leonidas-daedalustag:it.mathworks.com,2005:Question/4359102018-12-15T16:49:41Z2018-12-15T16:49:41Zhow can i get an improved Euler's method code for this function? dy = @(x,y).2*x*y;
f = @(x).2*exp(x^2/2);
x0=1;
xn=1.5;
y=1;
h=0.1;
fprintf ('x \t \t y (euler)\t y(analytical) \n') % data table header
fprintf ('%f \t %f\t %f\n' ,x0,y,f(x0));
for x = x0 : h: xn-h
y = y + dy(x,y)*h;
x = x + h ;
fprintf (
'%f \t %f\t %f\n' ,x,y,f(x));
end Ibrahem abdelghany ghorabhttps://it.mathworks.com/matlabcentral/profile/authors/14369066-ibrahem-abdelghany-ghorabtag:it.mathworks.com,2005:Question/4359092018-12-15T16:49:32Z2018-12-15T16:49:32Zi am doing a face recognition project and i want to use pca for feature extraction.. i did the database entry but i wanna extract the features and also i wanna connect my laptop camera to the code via gui to take a snapshot to be my desired image that i want to compare to my database.Mohamed Abd El Fattahhttps://it.mathworks.com/matlabcentral/profile/authors/14176018-mohamed-abd-el-fattahtag:it.mathworks.com,2005:Question/4359062018-12-15T16:19:33Z2018-12-15T16:48:10ZHow to make plot from if statement?% Hi I am really stuck and would very much appreciate help!
% I want to make a graph that looks like this:
% Here is my code:
x = linspace(-5,5,50);
if (x>-2 & x<0)
Y = x*1.5+3
elseif (x>0 & x<2)
Y = x*(-1.5) + 3
else
Y = 0
end
plot(x,Y)
% How can I plot this?Agnes Lindstenhttps://it.mathworks.com/matlabcentral/profile/authors/13485021-agnes-lindstentag:it.mathworks.com,2005:Question/4358962018-12-15T14:02:46Z2018-12-15T16:42:47ZWhy my subplot imshow not equally. Hi, I have a problem. My subplot imshow not equally even though image size is equally.
k = 1;
for i=1:2:col_size
m = 1;
for r=1:rml
n = 1;
for c=col(i):col(i+1)
letter(m,n) = ime(r,c);
n = n + 1;
end
m = m + 1;
end
if size(letter,2) >= 6 && size(letter,1) <= 90
subplot(1,(col_size/2),k);
imshow(letter);
k = k + 1;
end
clear letter;
end
Suttipong Pramuansinhttps://it.mathworks.com/matlabcentral/profile/authors/14372374-suttipong-pramuansintag:it.mathworks.com,2005:Question/3597712017-10-05T08:27:00Z2018-12-15T16:27:54ZHow to read depth map with .mat extension as a depth image - Make3D datasetDear Friends,
My question is related to Make3D dataset.
http://make3d.cs.cornell.edu/data.html#imagelaserstereo
Actually, I want to use Make3D Laser+Image dataset (400 original images and 400 align depth map from the outdoor scene).
The depth map is a mat file with 55x305x4 - double structure:
* *Laser Range data with Ray Position*.
* Data Format: Position3DGrid (55x305x4)
* Position3DGrid(:,:,1) is Vertical axis in meters (Y)
* Position3DGrid(:,:,2) is Horizontal axis in meters (X)
* Position3DGrid(:,:,3) is Projective Depths in meters (Z)
* Position3DGrid(:,:,4) is Depths in meters (d)
The size of original images is not the same as the depth map, original images all in resolution 2272x1704.
Could you please let me know how can I read (open) the depth map files like as a depth image that is shown in bellow.
I appreciate your help.salma samieihttps://it.mathworks.com/matlabcentral/profile/authors/3764071-salma-samieitag:it.mathworks.com,2005:Question/4356962018-12-14T07:37:19Z2018-12-15T16:27:28ZHow can I detect that which squares are ticked in the image?How can I detect that which squares are ticked in the image?
I'm think use the normxcorr2 or imshowpair to compare the original image with ticked image, but I not sure how to do this.
Original Image:
AlexMThttps://it.mathworks.com/matlabcentral/profile/authors/8178244-alexmttag:it.mathworks.com,2005:Question/4359072018-12-15T16:26:01Z2018-12-15T16:26:01Zuniform random number signal II-DOF comparation with Simulink and SimscapeI need to compare the results of a Simulink-model and the same model created using Simscape. The two models are a representation of a quarter car on different kind of roads. The first road is a step function with a height of 5cm at 5 seconds. As you see the resulting graph (tijdrespons stapprofiel) the curve that represents Simulink and Simscape are somewhat the same. I think the difference is due to the different solver is used by Simscape and Simulink.
When I replace the step function by a random universal number generator (with minimum = 0 and maximum = 0.02), the difference between Simscape and Simulink is quite big. It's such a large difference that I think, I've made a mistake. I also inserted the resulting (wrong) graph.
So, my questions are
Why is there such a big difference between Simulink and Simscape?
What I'm doing wrong because of the big difference? So, what I've misconfigured?
I've attached the four files:
A MATLAB-function for generating the parameters
A MATLAB-script for creating the graphs and setting up the parameters for the random road profile on both Simscape and Simulink
The Simulink-model for the random road profile
The Simscape-model for the random road profile
Jonathan Cazaerckhttps://it.mathworks.com/matlabcentral/profile/authors/7222746-jonathan-cazaercktag:it.mathworks.com,2005:Question/4359052018-12-15T16:11:16Z2018-12-15T16:12:56ZCreate a Matlab Function with the same input of a S-FunctionDear all,
My simulink model contains a SFunction written in Matlab.
If I try to compile the model in Rapid Acceleration Mode the following error is provided.
I read that a soluton is to use a Matlab Function block instead of an SFunction because my code is written in Matlab.
My function needs the following parameters that are provided to an SFunction by default: t, x, u, flag
The outputs of my function are [sys, x0, str, ts] even if only sys is the output of the SFunction Block.
How can i create a Matlab function block that receives the same inputs and get out the same output? Just for example, Where is the flag input?
Thanks
MFile S-functions without a
corresponding TLC file are not supported. You can inline
your S-function (name) by creating a TLC file for it.
You can also remap your S-function to C by creating a
corresponding C Mex source file and a name.tlc file in
the same directory as the MFile S-function which contains
(on the first line):
%%CallAsCMexLevel1
or
%%CallAsCMexLevel2
Antonio Parzialehttps://it.mathworks.com/matlabcentral/profile/authors/3463559-antonio-parzialetag:it.mathworks.com,2005:Question/2526192015-11-04T04:26:57Z2018-12-15T16:12:28ZHow to extracting a SHAPE,TEXTURE,REGION,BOUNDARY Features from IMAGES? extracting a SHAPE,TEXTURE,REGION,BOUNDARY Features from IMAGESSelva Karnahttps://it.mathworks.com/matlabcentral/profile/authors/4733665-selva-karnatag:it.mathworks.com,2005:Question/4358492018-12-14T23:08:14Z2018-12-15T16:10:49ZHow to calculate multiplying two matrices using (for) and (if) loops together ???How to calculate multiplying two matrices provided that the number of line elements in the first matrix equals the number of column elements in the second matrix (using the loop (for) and (if) together) thank youhcourah samehttps://it.mathworks.com/matlabcentral/profile/authors/14369858-hcourah-sametag:it.mathworks.com,2005:Question/4358192018-12-14T18:56:44Z2018-12-15T16:05:13ZIdentify shape in binary picture make it smooth and ignore resti am trying to identify forged parts of an image and i am having results like the picture below.
How can i :
identify the bigest object in the picture
make borders for the object and fill it in, in order to be smooth
remove any remaining part from the image
in which direction should i go?
lvashttps://it.mathworks.com/matlabcentral/profile/authors/13643452-lvastag:it.mathworks.com,2005:Question/4358822018-12-15T12:15:30Z2018-12-15T15:59:57ZHow can I get the subfolders to expand?Hello, I am trying to select a folder and set that folder as a root node of a graphical tree so as to be able to open the subfolders of the tree recursively. I am using:
tree= uitree ('v0', 'Root', uigetdir, 'Parent', []);
I am able to select a folder and it is set as the rootnode. When I click on the folder it opens and all the files and subfolders appear, however I am unable to open the subfolders. Whenever I click on the + to the left of the subfolders the + just disappears. Is there a way to solve that?
Any help appreciated. Thank you.Fatima Mansourhttps://it.mathworks.com/matlabcentral/profile/authors/13764834-fatima-mansourtag:it.mathworks.com,2005:Question/3799202018-01-31T05:10:40Z2018-12-15T15:52:47Zhow to find the height and width of an object <</matlabcentral/answers/uploaded_files/103022/A.jpg>>
I want to find the height and width of this image
I'd tried with this code but it does not give me the correct answer.
image1 = imread('C:\Program Files\MATLAB\R2016a\bin\WP_20180131_08_54_51_Selfie.jpg'); %Reads the image from location
I = rgb2gray(image1); % changes RGB input image into grayscale for edge detection
subplot(2,2,1);
image(image1); %Displays image
subplot(2,2,2);
image(I);
BW = edge(I); %detects edges in the grayscale image (only in gray scale)
[r1,c1] = find(BW);
subplot(2,2,3);
spy(BW);
x2 = max(r1);
x1 = min(r1);
X = x2 - x1
y2 = max(c1);
y1 = min(c1);
Y = y2 - y1
subplot(2,2,4);
imshow(BW);Rangika Markhttps://it.mathworks.com/matlabcentral/profile/authors/9026710-rangika-marktag:it.mathworks.com,2005:Question/231692011-12-06T05:06:48Z2018-12-15T15:50:09ZSlope Magnitude Technique with Sobel OperatorI have to extract shape by
Slope Magnitude Technique with Sobel Operator
Slope Magnitude Technique with canny Operator
Slope Magnitude Technique with roberts Operator
can anyone tell hoe to process
I have to extract the shape using three methods,i have posted for other three methods ,i colud not find any answer,else is there any methods other than these to extract shape
please helpPathttps://it.mathworks.com/matlabcentral/profile/authors/3009067-pattag:it.mathworks.com,2005:Question/4358992018-12-15T14:35:02Z2018-12-15T15:49:37Z1-hour to 6-hour aggregation?Hi all, I have rainfall data in hourly format. I want to aggregate the data to 6 hour sum data.
For ex.
01.00 5
02.00 4
03.00 6
04.00 1
05.00 9
06.00 5
the new data will be;
30 mm
Is it possible with matlab? Hüsamettin Taysihttps://it.mathworks.com/matlabcentral/profile/authors/12160415-husamettin-taysitag:it.mathworks.com,2005:Question/4359022018-12-15T15:03:21Z2018-12-15T15:42:52Zi need classification toolbox.hello guys i have stprtool ( https://cmp.felk.cvut.cz/cmp/software/stprtool/manual/index.html )
but some part of this doesn't work (svm classification for example )
someone has the right toolbox?Hossein Saberihttps://it.mathworks.com/matlabcentral/profile/authors/14013691-hossein-saberitag:it.mathworks.com,2005:Question/4359012018-12-15T14:52:37Z2018-12-15T15:42:51ZPlot without axis but with backgroundHi. I have a plot without an axis and I want to add a background around my plot. I want to do something like this plot in a picture
t=0:0.1:10;
y=sin(t);
plot(t,y);
xlim([-1,11]);
ylim([-1.1,1.1]);
axis off
set(gcf,'InvertHardCopy','off','Color','white');
saveas(gcf,'plot_test.jpg','jpeg')
Krzysztof Lesniakhttps://it.mathworks.com/matlabcentral/profile/authors/14305798-krzysztof-lesniaktag:it.mathworks.com,2005:Question/2703032016-02-27T10:31:44Z2018-12-15T15:41:37Zfind distance of points to centre of object?hi,
how can find the distance of a,b and c to the centre of object (red point) in a binary image. I've found the the centre, but finding distances of a,b,c looks difficult to me. thank you.
<</matlabcentral/answers/uploaded_files/46265/3.jpg>>
Abohttps://it.mathworks.com/matlabcentral/profile/authors/5840315-abotag:it.mathworks.com,2005:Question/4346582018-12-09T00:05:39Z2018-12-15T15:26:16Zmy own DCT2 and IDCT2 SolvedHey guys i am trying to make my own DCT2 and IDCT2 for school but
i can't find any error -> this is how i checked that it is not working ( as i know when i will do B=DCT2(vector) and then C=IDCT2(B) C will equal vector)
( this is exacly for 8x8 blocks and is use in JPEG coder )
Here is photo what exactly i have to do
DCT
and here is code
% dct2
function [ F ] = doDCT2( v2 )
N=8;
F=zeros(N,N);
for u=0:1:N-1
for v=0:1:N-1
vC=getC(v);
uC=getC(u);
temp=0;
for x=0:1:N-1
for y=0:1:N-1
temp =temp+v2(u+1,v+1)*cos(((2*x+1)*pi*u)/16)*cos(((2*y+1)*pi*v)/16);
end
end
F(u+1,v+1)=vC*uC*(1/4)*temp;
end
end
end
%c(u)
function [ C ] = getC( N )
if N==0
C=1/sqrt(2);
else
C=1;
end
end
%IDCT2
function [ F ] = doIDCT2( v2 )
N=8;
F=zeros(N,N);
for u=0:1:N-1
for v=0:1:N-1
vC=getC(v);
uC=getC(u);
temp=0;
for x=0:1:N-1
for y=0:1:N-1
temp =temp+vC*uC*v2(u+1,v+1)*cos(((2*x+1)*pi*u)/16)*cos(((2*y+1)*pi*v)/16);
end
end
F(u+1,v+1)=(1/4)*temp;
end
end
end Pawel Gagatekhttps://it.mathworks.com/matlabcentral/profile/authors/11692631-pawel-gagatektag:it.mathworks.com,2005:Question/1430962014-07-23T20:52:21Z2018-12-15T15:23:07ZSolving a system of linear differential equations with matlabI have a general question. I used dsolve to solve a normal system of linear equations and got a answer completly different then the one I got when I solved by hand. I know the one I did by hand is right because the solution corresponds with that of the textbook. So how is it that matlab gives a different answer but yet it is also correct?Adamhttps://it.mathworks.com/matlabcentral/profile/authors/5259679-adamtag:it.mathworks.com,2005:Question/3851912018-02-27T16:30:56Z2018-12-15T15:22:34ZHow to solve a system of equations?I try to solve a non=linear equtions system, but it doesn't work. I missed something?
F=@(x)[sqrt((x(1)-5)^2 + x(2)^2 + x(3)^2 )-sqrt( x(1)^2 + (x(2)+10)^2 + x(3)^2) +0.34;
sqrt(x(1)^2 + (x(2)+10)^2 + x(3)^2 )-sqrt( x(1)^2 + (x(2)-10)^2 + x(3)^2);
sqrt( x(1)^2 + (x(2)-10)^2 + x(3)^2 )-sqrt( x(1)^2 + x(2)^2 + x(3)^2)];
x0=[50;0;0];
fsolve(F,x0)
Jessie Besselhttps://it.mathworks.com/matlabcentral/profile/authors/10084296-jessie-besseltag:it.mathworks.com,2005:Question/4018062018-05-21T17:58:16Z2018-12-15T15:22:05ZRecursive Solution Of System Of lInear EquationsGiven a square upper triangular matrix A and a solution column b.
Write a recursive algorithm to find the vector x
So the end case is at the last coefficient we have
x_n=b(end)./A(end,end)
what will be the recursive call? how can I save a vector in a recursive function? it will start over and erase the vector? Harel Harel Shattensteinhttps://it.mathworks.com/matlabcentral/profile/authors/5317444-harel-harel-shattenstein