Answered
Matlab: Nested PDEG functions
@Soheil Smz: what do you expect to happen? You have two possible solutions: # Define the variable at the start of the parent ...

10 years ago | 0

| accepted

Answered
fopen function how to use a variable name to select a file present in a folder?
The mistake is on this line: file=files(1); You need to use <http://www.mathworks.com/help/matlab/matlab_prog/access-dat...

10 years ago | 0

| accepted

Answered
How to create a structure in which variables can be labelled with a string?
Just use *one* structure |S| and <http://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variables.html dyna...

10 years ago | 0

Answered
how to multiply a N*N*M matrix with 1*M array
This works correctly, and is fast and efficient: A(:,:,1)=[1 1; 1 1]; A(:,:,2)=[1 1; 1 1]; A(:,:,3)=[1 1; 1 1]; b=...

10 years ago | 0

| accepted

Answered
Using fprintf for matrix
>> X = [1,2;2,4;5,6]; >> Y = [1;3;4]; >> fprintf('-%d: %d %d\n', [Y,X].') -1: 1 2 -3: 2 4 -4: 5 6 It is wort...

10 years ago | 7

| accepted

Answered
Is it possible write subroutines with input arguments in MATLAB?
Use just one output: a <http://www.mathworks.com/help/matlab/structures.html structure>. Then you can specify whatever fields...

10 years ago | 0

Answered
Write a substring in a Text file with existing string
Change the <http://www.mathworks.com/help/matlab/ref/fopen.html |fopen|> file permission from |'w'| (write) to |'a'| (append): ...

10 years ago | 0

| accepted

Answered
"Or Statement in And statement" using if operator
You need to use <http://www.mathworks.com/help/matlab/ref/specialcharacters.html brackets> to group the logical statements toget...

10 years ago | 3

| accepted

Answered
Matrix indexing using a vector
You can use <http://www.mathworks.com/help/matlab/ref/sub2ind.html |sub2ind|> for this: >> A = zeros(4,3); >> col = [2;1...

10 years ago | 1

| accepted

Answered
give a id to same values in a cell
You can use <http://www.mathworks.com/help/matlab/ref/unique.html |unique|>: >> C = {'aa', 'aa', 'ab' ,'ab', 'ab', 'ac', 'a...

10 years ago | 1

| accepted

Answered
Given 2 vectors X,Y both of length N, How do I act on every single term in X with every single term in Y into a N by N matrix?
>> X = [1,2,3]; Y = [1,2,3]; >> exp(bsxfun(@plus,X.',Y)) ans = 7.3891 20.0855 54.5982 20.0855 54...

10 years ago | 0

| accepted

Answered
I have a 720 x 296 matrix, how can I specify for repeat this n times in some kind of loop like:
Here are three very easy ways to repeat values in a loop. *Method One: define a vector before the loop:* >> vec = repmat...

10 years ago | 0

Answered
Inverse index problem.
You can create the logical inverse by using a <http://www.mathworks.com/help/matlab/ref/not.html logical not |~|>: ind_occ =...

10 years ago | 1

| accepted

Answered
Vectorization of a nested for loop, where inner counter depends on outer one.
>> [X,Y] = meshgrid(3:6); >> idx = Y>=X; >> sum(factorial(Y(idx)) ./ factorial(Y(idx)-X(idx))) ans = 2274

10 years ago | 0

| accepted

Answered
It's a little bit weird.
It is not weird at all. You just need to learn about <http://www.mathworks.com/help/matlab/matlab_prog/floating-point-numbers.ht...

10 years ago | 1

Answered
how to generate all possible combination from a sequence
>> perms(1:3) ans = 3 2 1 3 1 2 2 3 1 2 1 3 1 2...

10 years ago | 3

| accepted

Answered
How to apply fprinf for matrix
This is MATLAB, so there really is no point in using an _ugly loop_ when you can do it much faster and simpler with just one <ht...

10 years ago | 1

| accepted

Answered
Hi folks, how do I write a program that would reference the original indices of a sorted list of inputs?
Inbuilt is easiest: [sx,sxindex] = sort(x) If you need to write your own program as homework then something like this wil...

10 years ago | 0

| accepted

Answered
assign vector to cell
New(:,1) = num2cell(k) <http://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-cell-array.html>

10 years ago | 2

| accepted

Answered
Center day of each month
>> tmp = eomday(2001,1:12); >> cumsum(tmp)-(tmp-1)/2 ans = 16.000 45.500 75.000 105.500 136.000 166.5...

10 years ago | 1

Answered
How can i remove all spaces from all lines in a text file?
Here is a fast solution in just three lines: >> fid = fopen('text_out.txt','wt'); >> fprintf(fid,'%s',strrep(fileread('t...

10 years ago | 1

Answered
match structures by table
You can do this easily using <http://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variables.html dynamic ...

10 years ago | 1

| accepted

Answered
Importing data without knowing number of columns
Here is some code that reads a text file with any number of columns. It works by reading the header line and using this to defin...

10 years ago | 1

Answered
Basic 'for' loop iteration
Why bother using a loop? MATLAB code can be so much neater! >> v = [1,2,3,2,3,1]; >> s = 0.1; % step size >> x = s*(1...

10 years ago | 0

Answered
Save New Variable to the Workspace for every iteration with a 'for' cycle
Exactly as Adam said in their comment, just use a 3D array like this: Q = randi(9,3,3); vec = [0,45,60,45,45,60,45,0]; ...

10 years ago | 0

| accepted

Answered
GUI by code dynamic
This is a classic example of how using |eval| makes code so obfuscated. Beginners often seem to think that using |eval| solves p...

10 years ago | 0

| accepted

Answered
i need to create a matrix from 2 vectors
*Method One* is a simple solution, but it only works when the grid has an odd number of rows: >> [X,Y] = meshgrid([0,1000,2...

10 years ago | 1

Answered
How can I solve the problem of colour map? (figure provided)
Start by reading the <http://www.mathworks.com/help/matlab/ref/scatter.html |scatter|> documentation. You can specify the color ...

10 years ago | 0

| accepted

Answered
how to write the percentage into pie chart?
L = {'A','B','C','D','E'}; X = [ 1, 3,0.5,2.5, 2]; H = pie(X); % T = H(strcmpi(get(H,'Type'),'text')); P = c...

10 years ago | 1

| accepted

Answered
"Undefined function or variable 'x'." for input of function
*1)* When I run your code exactly as it is I get a totally different error: >> VecField(1,2,0,100) ??? Error using ==> q...

10 years ago | 0

| accepted

Load more