w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » MATLAB » Page 1
Maximum Likelihood, Matlab
Regarding the presence of several maxima: this issue will occur when dealing with a function that is not convex. It can be partially solved by multi-start optimization, which essentially means that you run the simulation multiple times in order to find as many maxima as possible and then selecting the 'highest' maximum from among them. Note that this does not guarantee global optimality, as the gl

Categories : Matlab

MATLAB avoid matrix wrapping in command window
You could do fprintf([repmat('%f ', 1, size(c, 2)) ' '], c');, which gave this output: 0.000000 0.818064 1.054641 0.342287 0.668041 0.717356 0.597756 0.804045 0.650459 0.815819 0.818064 0.000000 0.778921 0.485276 0.322136 1.157594 0.833495 0.363079 0.185730 0.060130 1.054641 0.778921 0.000000 0.917058 0.529164 0.815812

Categories : Matlab

MATLAB: Error in fig2texPS
This might not be the answer you are looking for, but there is the marvelous matlab2tikz that does the job of conversion of figures quite nicely, which you could use as an alternative to fig2texPS.

Categories : Matlab

substitute the derivative of a function in a symbolic expression
MATLAB interprets that you are doing a nested index call. It thinks that you are doing D(x), then whatever result of this you are indexing into the array with t. What you should do instead is nest a diff(x,t) call inside of the second parameter of subs, then do your substitution. Therefore: subs(ans, diff(x,t), 3);

Categories : Matlab

How to use MATLAB functions in Visual C++?
You can access MATLAB from Visual Studio and Eclipse through the MATLAB engine interface. As long as you MATLAB installed you just need to set the right paths in your project settings and link in 3 library files. Here is a link to the description and setup. http://www.mathworks.com/help/matlab/matlab_external/introducing-matlab-engine.html http://www.mathworks.com/matlabcentral/answers/100603-

Categories : Matlab

Size of cell elements
Store the counts of the DataCell into an array, then "nomalize" it: data_counts = cellfun(@(x) size(x,1), DataCell); prior = data_counts / sum(data_counts(:)); The data_counts(:) is just a funny way of summing all the elements of data_counts, no matter what shape they're in.

Categories : Matlab

Updating Waitbar throws error while using matlabpool
I think the thing you did 'wrong' was to use a waitbar inside a parfor loop haha. But seriously I'm afraid that's because iterations are not executed in order inside a parfor loop so using a regular waitbar is prohibited because of the way information is shared between the Matlab client and the workers executing the loop. Even if you did not write matlabpool('open',4) MATLAB would have opened it s

Categories : Matlab

Why am I getting an error when trying to use vertcat?
You can only concatenate vertical arrays (of type string) if they are the equal size i.e. the rows and columns must be identical. A similar question was answer here - http://math.stackexchange.com/questions/449791/why-do-i-keep-getting-a-vertcat-error-in-matlab. May be this will help you understand what you are up against? A tip for you would be to pad the difference using white-space " "? This w

Categories : Matlab

Creating new matrix out of one column by order of two other columns
You can use this method [~,J1,K1] = unique(A(:,1)); [~,J2,K2] = unique(A(:,2)); sz = [numel(J1) numel(J2)]; B = nan(sz); B(sub2ind(sz, K1, K2)) = A(:,3); first use unique to gather the unique items and their indices in the original column. The size of B is determined by number of unique elements in first and second column of A. Now use linear indexing (obtained using sub2ind) to put the values

Categories : Matlab

Normalized Image Histogram
I assume you use the mean of the three components instead of the function rgb2gray because it has some advantages in your case. (rgb2gray does something similar: it uses a weighted sum). Subtracting the minimum and dividing by the maximum doesn't convert your image to binary. It will only scale all values to the range (0,1), which is the case in your example. This only means that all values are

Categories : Matlab

Change figures into ppt slides
Break your code into sections, each section of your published code will get its own slide. This really should be mentioned in the documentation but I don't see it. Compare the publishing outputs from the following: % One Slide x = 1:10; y = 1:10; h.f1 = figure(); plot(x,y); h.f2 = figure(); plot(x,y); vs %% % 3 Slides x = 1:10; y = 1:10; %% h.f1 = figure(); plot(x,y); %% h.f2 = figure();

Categories : Matlab

Creating variable names using cells from an array in Matlab
You might want to consider using T = readTable('mydatafile.txt'). This allows you to load a file with seperate columns and access those colums using their column name, for example like this: T.MyFirstColumn. See the manual on readtable for some examples.

Categories : Matlab

Matlab handling values after getting them in edit text
MATLAB will generate a callback function for your "run" button in the m-file of your GUI: function yourpushbutton_Callback(hObject, eventdata, handles) where handles is a structure containing all handles of the GUI. You can get the parameters from the edit text fields and call your function in this callback function. To get the text, use text = get(handles.edittext1,'String');

Categories : Matlab

How to write a inline function which will accept two arguments in MATLAB
While its probably not what you want, I think this is one situation where I would use a for loop, as nchoosek only accepts an integer for its k value: nCk = @(n,k)(nchoosek(n,k)); n = 3; for k = 1:2 disp(nCk(n,k)); end Though if you do it this way, then the inline statement is likely redundant, so it could be reduced to: n = 3; for k = 1:2 disp(nchoosek(n,k)); end

Categories : Matlab

How to acquire external analog input in matlab using audio line in?
It's possible to use the method you mentioned, but be careful with signal strength. I used to connect a laptop's speaker output to a mic input, and record waveform of mic. The waveform was perfect as long as speaker output fell into the right range (only 1/10 of its max amplitude generated by laptop roughly). So I would suggest you start from very low amplitude, for example 50 mV, and see what you

Categories : Matlab

How to change image pixels values?
It appears you only want to change the image values based on the y coordinate, so create a new matrix y like this: y = (1:height)' * ones(1,width); where height and width are the size of your image: [height, width] = size(v); then create your image v: v = a.*(y.^2) + b.*y + c; This will work if a, b, and c are single values or matrices with the same size as y. Hopefully that is what you

Categories : Matlab

MATLAB calculating distances in a loop
Change your coord assignment to the following: coord = [p1; p2]; The way you have it, it is storing all of the x, y pairs on the same row, as a 1x4 matrix. The above method stores it as a 2x2 matrix and pdist gives an answer.

Categories : Matlab

Piecewise constant surface in MATLAB
You can just use logical indexing: x = -2:.01:2; y = -15:15; [X,Y] = meshgrid(x,y); %// Make domain h2=zeros(size(X)); h2(5<Y & Y<10 & 0<X & X<1)=1; h2(0<Y & Y<5 & 0<X & X<1)=-1; h2(-5<Y & Y<0 & 0<X & X<1)=1; This statement: 5<Y & Y<10 & 0<X & X<1 returns a matrix of 1's and 0's where a 1 means that

Categories : Matlab

segregating elements and its index from matrix
You can do this fairly easily using max: A = [NaN 0.9 0.8 0.7; NaN NaN 0.7 0; NaN NaN NaN NaN]; [max_val,max_ind] = max(A,[],2); max_ind(isnan(max_val)) = size(A,2); The second output of max is the index of the maximum value. By default it will ignore NaN values, unless every value is NaN, in which case it returns 1. The 3rd line of this snippet simply finds values where the maximum value is Na

Categories : Matlab

Matlab index with specific values using loop
Not sure exactly what you are trying to achieve, but I think that you can fix your loop as follows: entries = 3; X =zeros(20,1); for ni = 1:entries n = input('Determine value for case :'); X(n) = input('Determine position:'); end

Categories : Matlab

Matlab: Incorrect estimates returned by fminsearch
Your problem does not seem to be convex. This means fminsearch will find a local minimum rather than a global minimum, and thus your result will be dependent on your initial estimation. You can check this by altering your theta0 value to for example theta0 = 0.99*ones(3,1); Which yields completely different results. One way of working around this problem is using a Monte Carlo method, which b

Categories : Matlab

MATLAB: solving symbolic matrix
This question has no need for any symbolic mathematics. Your A1 and A3 matrices are defined numerically. All you have to do to find the entries in A2 is to invoke the inverse operator () between A1 and A3. Specifically, if you are given: A1 * A2 = A3 , to find A2, you would do: A2 = A1^{-1} * A3 You would find the inverse of A1 and multiply this with A3. You can easily do this in MATLA

Categories : Matlab

How can I (efficiently) compute a moving average of a vector?
The conv function is right up your alley: >> x = 1:8; >> y = conv(x, ones(1,5), 'valid') y = 15 20 25 30 Benchmark Three answers, three different methods... Here is a quick benchmark (different input sizes, fixed window width of 5) using timeit; feel free to poke holes in it (in the comments) if you think it needs to be refined. conv emerges as the fastest approach;

Categories : Matlab

Stopping criteria matlab iteration
Well, somehow you need to compute the 'error' you are doing in each iteration. In your case it would be something like this: iter = 0; tolerance = 1e-6; error=1; x=F(x); while(error>tolerance) x2=x; x=F(x); error = x-x2; iter= iter + 1; end Note how at the beginning the error is set to 1 so we make sure it goes inside the loop. We also compute the first instance

Categories : Matlab

How can i write bits to a file in matlab
No, file operations are inherently byte-oriented. You may not write partial bytes out. You need to concatenate all the bits into a string of bytes, and write that string out. The code might look something like this: allbits = cat(2, V{:,3}); % concatenate all bits into one giant binary string npadding = 8 - mod(length(allbits), 8); % number of bits needed to produce an even multiple of 8 if(

Categories : Matlab

MATLAB How to move a menu to center of screen
A possibility would be to copy the content of the menu.m file into a new function, rename it and add this line: movegui(menuFig,'center'); on line 229. Although I must say that it might be illegal or be against the terms of service...if that's the case I'm not even sure I should propose this. Anyhow by typing edit menu in the command window one can see that the function simply creates a figure

Categories : Matlab

Failing to create an algorithm for a probabilistic simulation
The sequence you are trying to generate is called a Markov chain and you can generate one with the help of a transition matrix. The transition matrix is an NxN matrix (where N is the number of possible states, four in your case) where the i-th row and j-th column tells you the probability of going from state i to state j. Naturally, the rows of the transition matrix must sum to one. For example, a

Categories : Matlab

Understanding output of cylinder function
The cylinder surface is not a function, so each (X,Y) pair is corresponding to different Z values (in your case - 0 and 1). If you look at the value you are getting, you will notice that for X and Y you are getting the same data in both rows, for Z you will get different rows.

Categories : Matlab

showing how numerical solution coming close to the real selution
I do not understand many things in your code, e.g. why BisectionM has two identical outputs under different variable names (sol, Roots), moreover only one output is used throughout the main function. Besides here is my guess what you might want: The figure shows how the numerical solution converges with respect to iteration number. For this you have to store the iteration results in a vector (s

Categories : Matlab

How to store the 2D image pixels into 1d array?
In your code, the quickest way (though not necessarily the most efficient, but most compatible with your code...) would be to allocate a 2D array and populate this array at each iteration. Referencing my previous post to you, the total number of times this loop iterates is (e-3) x (f-3) times. Therefore, allocate a 2D array like how you said in your post. Only this time, replace count with (e-3

Categories : Matlab

installing libsvm on Mac (OSX 10.9.2)
I think the following answer from the matlab support might be helpful (http://www.mathworks.com/matlabcentral/answers/103904-can-i-use-xcode-5-as-my-c-or-c-compiler-in-matlab-8-1-r2013a-or-matlab-8-2-r2013b): The Mac OS X 10.7 SDK, available in Xcode 4.1 through 4.6, is used by MEX and related capabilities. This SDK is no longer available in Xcode 5, resulting in errors similar to the foll

Categories : Matlab

Simulation Velocity of a harmonic oscillator system
Your code can return a negative value as randn is a normally distributed random number with standard deviation 1. In theory this could return any number and there is ~15% chance it will be less than -1. You are also correct than you should update x at each step. I would take x as an input into getPos and xdot as an output. Then add another step to update the position.

Categories : Matlab

read input file Matlab
Is this what you are looking for...? I think you have to use %s %s as a format to text scan and not a float because a vector cannot be converted to a float for example. I changed this A = textscan(fid,'%s %s','Delimiter',' '); to include %s %s. Also, I think you want to concatenate along the first dimension rather than the second. I think you actually want to create a key/value pair of the inpu

Categories : Matlab

m_line boundary for stereographic map
I think the function is just made to find points on a map, and connect them with a straight line (As you currently see happening). A way to get what you want might be to work around this with a polygon that consists of many points, for example: bndry_lon=[linspace(0,125,100) 125 0 0 ]; bndry_lat=[linspace(86,86,100) 90 90 86 ]; If you believe the function is capable of producing the curved

Categories : Matlab

Change data in intra frame of MPEG file in matlab
I am assuming that by Intra-frame you mean I-frames. There is no way to determine whether a frame is an I, P or B-frame after it has been decoded. One has to look at the raw encoded bitstream to do this. A tool such as ffprobe can help you with this. You can do this round-about thing if you really want to: Download ffmpeg tools. It has a function or utility called ffprobe. On the system termina

Categories : Matlab

How to find the index of dependent column in sparse matrix
I don't know why you want discuss this in the sparse context, but apart from simply checking each dependency you could do it simultaneously. I suggest something like %% create some data... A = double(rand(3,3) > 0.5) %% create linearDependencyMatrix with % important % linearDependencyMatrix(i,j) == 1 % part % iff

Categories : Matlab

My simple simulink model runs too fast
1) I had the same issues with some interactive simulations where the CPU would make them run too fast for the user to interact. Using a Simulink Real Time Execution Block brought the solution, despite it gives heavy CPU load due to the solution it uses. With this, if you define a 10sec simulation, that's what it will last. If you don't want to pass through this burden, just lengthen your simulatio

Categories : Matlab

Rotating labels and superscript in Matlab
I recommend you to use format_tick instead of xticklabel_rotate, the former allows you to format your labels as TeX objects and also has positioning options. Make the following changes in your code to get the desired output: Change from: % Rotate labels xticklabel_rotate([],45,[],'Fontsize',fsizeMed,'interpreter','none') to: % Rotate labels format_ticks(gca, XTL_prim, [], [], [], 45) Add a

Categories : Matlab

Could anyone help me to solve this code please?
You have a problem with interp1 usage. p = interp1(t,p,T) - this returns a vector 'p = interp1(t,p,method,'pp') - this returns a structure with piece-wise function. Docs are here. Also, you can use ppval to get values from piece-wise function. And the last note - there is a warning in Matlab r2014a: Warning: INTERP1(...,'PP') will be removed in a future release. Use GRIDDEDINTERPOLANT instead.

Categories : Matlab




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.