Answered
find the longest monotonically increasing subsequence of a sequence of n numbers?
A simple recursive function does the trick: function V = longestMono(S) %S = [18,32,5,6,17,1,19,22,13]; V = []; for k = 1:nu...

8 years ago | 1

| accepted

Answered
How to plot a simple function that has a variable?
You can do this very simply by defining a normal function handle: >> F = @(x,a) x.^2 + a*x - 6; >> X = -10:.1:10; >> plot(X,F...

8 years ago | 0

Answered
replace all values of cells between two positions
For an aribtrary number of rows and an aribitrary number of indices using loops is about the most straightforward way of doing t...

8 years ago | 2

| accepted

Answered
I have a 16x31x17 double matrix which various different values. I want to find out the location of one single value which is 305.3. How can i do that ?
Where A is your 16x31x17 array: X = abs(A-305.3)<1e-5; [R,C,P] = ind2sub(size(X),find(X))

8 years ago | 0

Answered
How to clear existing array size? I am getting "Subscripted assignment dimension mismatch" Error.
clear is rarely needed in well written code. It is usually simpler and more efficient to just let MATLAB manage the memory by co...

8 years ago | 0

Answered
How to convert a string (eg ABCD12134) i.e a combination of text and numbers to a double ?
>> s = 'ABCD12134'; >> sscanf(s,'%*[^0123456789]%f') ans = 12134 >> sscanf(s,'%*[A-Z]%f') ans = 12134 >> str2double(regex...

8 years ago | 0

Answered
how to count the number of different elements in two matrices
Simpler: mean(a~=b)

8 years ago | 1

Answered
How to cell array of string to 3D matrix?
This converts your supplied cell array (attached) into a numeric array: >> C = cellfun(@(s)sscanf(s,'%f'),AB,'uni',0); >> A = ...

8 years ago | 0

| accepted

Answered
Find empty cells in excel
You used the wrong kind of indexing. You need to use curly braces: isempty(raw{6,1}) ^ ^ The differ...

8 years ago | 0

Answered
create indexes of x in a for loop
It is not very clear what you are trying to achieve, but it is possible to store a function handle in a cell array: C = cell(1...

8 years ago | 0

Answered
Concatenate rows within a 3D cell array
Try something like this: baz = @(c) horzcat(c{:}); foo = @(x) cellfun(baz, num2cell([x.A;x.C;x.E],1), 'uni',0); arrayfun(foo,...

8 years ago | 0

| accepted

Answered
Unable to save variables and figures of large arrays
"what is the meaning of this error?" The .fig file format is really just a .mat that stores all of the objects in a figure. Mos...

8 years ago | 0

| accepted

Answered
How to load a .mat file and make all the variables from that .mat file to be global variables?
Always load any .mat file into an output argument (which is a structure): S = load(...); This avoids several issues related to...

8 years ago | 1

| accepted

Answered
How to loop through cell arrays
S = size(H); for rx = 1:S(1) for cx = 1:S(2) H{rx,cx} end end

8 years ago | 0

Answered
Is there a function/command call that does 2-d logical
Either you can get a vector of only the values that you want (like you were getting), or you can have a matrix by replacing the...

8 years ago | 1

Answered
My 'for' loops aren't altering anything except a few points in my matrices
Problem: it is very simple: you are using a syntax that does not do what you think it does. This syntax n_B > i > 1 is actu...

8 years ago | 0

| accepted

Answered
How to count repetition of a row in a matrix?
>> M = [1,2; 2,3; 1,5; 2,3; 1,4; 1,6; 2,3; 8,9]; >> R = [2,3]; Method one: eq: and all: >> nnz(all(M==R,2)) ans = 3 For MA...

8 years ago | 0

| accepted

Answered
Saving or using callback values
The easiest way to do this is to use a nested function (which in this case is your callback function): function val = myfun() ...

8 years ago | 0

Answered
How to plot data from cell array based on a logical array?
Far too complex. You are trying to define strings which will be magically evaluated and converted back into data. The syntax yo...

8 years ago | 1

| accepted

Answered
I cant get my nested if statements to work, is the indentation wrong?
Your indentation is messed up. You should use the default indentation of the MATLAB editor: select all of the code press ctrl+...

8 years ago | 0

Answered
getting error for my program as " Error using * Inner matrix dimensions must agree." on line 42 . can someone help me resolve this issue?
The error occurs here: 1i*2*pi*(n3.*I0)*(Lnl./L)*((abs(E1)).^2) ^^^^^^^^^^^^^^^^ % scalar ...

8 years ago | 1

Answered
count the number of transitions from 0 to 3 in cells in cell array
Here is a simple method based on logcal arrays, demonstrated on two Nx4 matrices in a cell array. The first matrix has two 0,3 t...

8 years ago | 0

| accepted

Answered
Finding the max value of a particular row in a cell array and then returning the values of the full row in a table
>> S = {[1,2,3;4,5,6],[3,4,6;7,8,9]}; >> A = cat(3,S{:}); >> [~,idx] = max(A(1,3,:)) idx = 2 >> V = A(1,:,idx) V = 3 ...

8 years ago | 0

| accepted

Answered
why condition become true in if/esle ?
"...here Vxp and Vxn both are same value(32.000); so the difference must be 0..." Evidently not true. "why it's happening ? an...

8 years ago | 1

Answered
How can I get an average of different matrices stored as separate .mat files?
Assuming that each file contains exactly one variable (a matrix) and that all matrices are the same size and type: S = dir('*...

8 years ago | 2

| accepted

Answered
How do you pause rendering of a figure until you're done setting properties?
This might work: # Find its parent figure (e.g. |gcf|) and set its |'Visible'| property to |'off'| # Change the properties ...

8 years ago | 1

Answered
how to return the solution of a vector of variables one time instead of indexing sol.x1, solx2..etc
You can dynamically access fieldnames: <https://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variables...

8 years ago | 0

| accepted

Answered
How to store multiple column vector generated from a for loop?
N = 41; A = nan(12,N); B = nan(12,N); C = nan(12,N); D = nan(12,N); for k = 1:N [A(:,k),B(:,k),C(:,k),D(...

8 years ago | 0

| accepted

Answered
I'm stuck debugging a simple code. Maybe I'm making a mistake by assuming that there no difference between when MATLAB executes instructions in a script and when MATLAB executes instructions from the command window.
_"I run this simple script, entitled "proj3numan", written exactly as you see here:"_ Nope. That error message shows how you ...

8 years ago | 1

| accepted

Answered
How can i find Inverse of an array of non negative integers ?
>> G = [4,1,2,5,3] G = 4 1 2 5 3 >> [~,S] = sort(G) S = 2 3 5 1 4

8 years ago | 1

| accepted

Load more