Answered
How to I create a function handle through recursion?
I don't see any reason why you need any recursion, basic vectorized code works just fine: V = 0:size(A,1)-1; F = sum(A(:,1).*t...

6 years ago | 1

| accepted

Answered
Automatisation of .mat files load and storing into a matrix
N = 20; C = cell(1,N); for k = 1:N F = sprintf('dx00%d.mat',k); S = load(F); C(k) = struct2cell(S); % if there ...

6 years ago | 0

Answered
Importing files in the right order
"Any simpel way to make this happen?" Method one: The simplest way is to rename the files with sufficient leading zeros, e.g. ...

6 years ago | 1

| accepted

Answered
saving workspace of each pair of variable in a loop
for ii = 1:numel(X) for jj = 1:numel(Y) ... your code fnm = sprintf('workspace_%d_%d.mat',ii,jj); ...

6 years ago | 0

| accepted

Answered
Matrix comparison with unequal sized matrices
N = nnz(B(1:end-1)>A(2:end)) Tested: >> A = randi(9,1,5) A = 2 5 7 2 6 >> B = randi(9,1,5) B = 3 9 5 ...

6 years ago | 0

| accepted

Answered
Why a matrix multiply a variable and then be divided by the same variable produce different results?
"I am confused by the code show above, b is just a number, so why the matrix multiply b and then divide the same b (line 5) woul...

6 years ago | 1

| accepted

Answered
find text in text file
>> T = readtable('temp0.txt','Delimiter','\t','ReadVariableNames',false) T = Var1 Var2 Var3 __________ ...

6 years ago | 0

Answered
Unknown error in my m.function
There are a few combinations of values for which your function does not define the output argument. If you call the function wit...

6 years ago | 0

| accepted

Answered
How to turn off text interpreter when plotting timeseries objects
One approach would be to set the interpreter for the entire figure before plotting (and reset it again afterwards): https://www...

6 years ago | 0

| accepted

Answered
I have multiple files. I need to combine info in the files.
As Rik suggested: av = a(:); bv = b(:); [X,Y] = ndgrid(1:10); M = [av(X(:)),bv(Y(:))]

6 years ago | 0

| accepted

Answered
reshape vector to matrix
A general solution for an arbitrary number of rows and columns: >> d = [1,2,3,4,5]; >> r = 4; >> m = hankel(d(1:4),d(r:end)) ...

6 years ago | 0

| accepted

Answered
combination of tables across columns
Where T1 and T2 are your two tables: T = [T1,T2]; T = T(:,[1,4,2,5,3,6])

6 years ago | 0

| accepted

Answered
Not enough input arguments
"Why is it said not enough input arguments at momentum1 = zeros(size(W1)); ?" Because you called the function without any input...

6 years ago | 0

| accepted

Answered
A loop for sorting tables
tblA = sortrows(Table1,{'Variable','Value'}); for k = 1:40 % or whatever the max 'variable' is. vnm = sprintf('Variable %d...

6 years ago | 1

| accepted

Answered
I there a way to call variables from my workspace into the genetic algorithm tool? (Without calling them from the fitness function)
"Is it possible to have variables in my fitness function (data.Die and data.DiePD in my case) that are in my worspace without ha...

6 years ago | 1

| accepted

Answered
using a value to find index in a matrix?
The simplest solution is to simply check for equality: idx = x==Matrix_A; which will return a logical array with true in every...

6 years ago | 0

| accepted

Answered
Extract unknown number of vectors from matrix
" num2cell would create separated cells with the n vectors of size, but sub2ind also does not run on cells." True, but you can ...

6 years ago | 1

| accepted

Answered
code to load my files from folder, add workspace variable and save to another folder
You don't need to load the file data, you can use save's '-append' option: fs = 128; for ... loop over all files, you need to ...

6 years ago | 1

| accepted

Answered
exceeded number of array elements
Ru is scalar, but in multiple locations you try to access Ru(2), e.g.: for u = 1:2 xX{u} = @(Beta) Ru(u)*cos(Beta) + sqrt( R^2...

6 years ago | 1

Answered
How to replace every non-0 number with the number in that place added to another number - no loops
I think it is neater to only define the index once: >> X = A~=0; >> A(X) = A(X)+B A = -6 0 -4 -3 -2 0 1 0 ...

6 years ago | 0

| accepted

Answered
Error "too many output argument" in function
"How should I do to fix the error?" If you want a function to return an output then the it must be defined in the function decl...

6 years ago | 1

| accepted

Answered
pass string variable to a function in uicontrol callback
Define the function to accept five input arguments: function correctAnswer(hCorrectAns,EventData,num1,randomVector,string1) an...

6 years ago | 0

| accepted

Answered
how do i plot til some x one function and then other
x = 0:0.1:20; y = min(12,x); plot(x,y,'-+') In a more general case, use logical indexing, e.g.: x = 0:0.1:20; y = x; y(y...

6 years ago | 1

| accepted

Answered
Index exceeds the number of array elements (1).
Your define angulo as a scalar (i.e. size 1x1): angulo= 15; and then a few lines later with i=2 you try to access its 2nd elem...

6 years ago | 0

| accepted

Answered
Inputting the function Sin(2x)Cos^2(0.5x)
x = linspace(0,2*pi,50); y = sin(2*x).*cos(0.5*x).^2; plot(x,y)

6 years ago | 0

Answered
Plot a variable within a function
"How should I plot Ca vs W curve after function has been evaluated" Return the required variables as the 2nd, 3rd, etc. functio...

6 years ago | 0

Answered
Invalid data type - converting to cell array to run functions
In both cases your code nests a cell array inside a cell array: dff{i} = num2cell(tot_dff(1,f_i(i):f_o(i))); % ^^^^^^...

6 years ago | 1

| accepted

Answered
Using an integral in a function
The problem is that in the "main file" you did not declare q_Max and f_1 as global. But rather than using global variables (whi...

6 years ago | 0

| accepted

Answered
Doubt about plotting in Matlab and finding intersect points
"...if I plot the circle with the lines, the circle deforms to an oval" axis('equal') https://www.mathworks.com/help/matlab/re...

6 years ago | 0

| accepted

Load more