Answered
How to flip every 5th row and column in matrix
>> M = repmat((1:12).',1,3) M = 1 1 1 2 2 2 3 3 3 4 4 4 5 5 ...

8 years ago | 0

| accepted

Answered
is there a way to extract a set of values from a structured array?
Use a <https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html comma separated list>: [meas.ti] See...

8 years ago | 0

| accepted

Answered
how to make a for loop for a binary number ?
In MATLAB binary numbers are normally stored as char vectors: >> x = '10010' x = 10010 >> x(3) ans = 0 >> bin2d...

8 years ago | 0

Answered
please help with multiplication and division function
The solution is simple: don't use cell arrays: A = [1;2;3;4;5;6;7]; B = [1;2;3;4;5;6;7]; C = (3*A-B)./2;

8 years ago | 0

Answered
How to increase the number of inputs and outputs of ndgrid
The trick is to use cell arrays and <https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html comma-separate...

8 years ago | 2

| accepted

Answered
odeFunction: List variables through loop
Writing to file is slow and unnecessary, it is simpler and faster to just make the string directly: >> Xs = sprintf(',x%d',...

8 years ago | 1

| accepted

Answered
How to merge adjacent NaN values into single NaN value in a vector?
No loops required, no tricks required, just basic MATLAB indexing: old = [1 2 3 NaN NaN 0 1 2 NaN 9 8 7 6 NaN NaN NaN 1 1];...

8 years ago | 3

| accepted

Answered
convert a txt file with complex numbers to a matrix
Why did someone put double quotes around perfectly good complex numbers? Here are three ways to approach the problem: 1. u...

8 years ago | 0

| accepted

Answered
How to randomly generate one non-zero element of each row from a matrix
In two lines: >> A = [1,5,6,7,0;2,0,0,4,2;0,0,3,4,0]; >> [R,C] = find(A); >> accumarray(R,A(A~=0),[],@(v)v(randi(nume...

8 years ago | 0

Answered
how to convert matrix size
reshape(s1,2882,2575) or reshape(s1,2575,2882).' depending on the order you want.

8 years ago | 0

| accepted

Answered
how to merge two matrix to one matrix ?
m = [x(:),y(:)] e.g.: >> x = [50.2124,50.2133,50.2134,50.2134,50.2137]; >> y = [26.385, 26.386, 26.387, 26.388, 26....

8 years ago | 0

| accepted

Answered
convert vector to matrix
>> a = [1,2,3,4,5,6]; >> M = tril(ones(4),-1); >> M(M>0) = a; >> M = M+M.' M = 0 1 2 3 1 0 4...

8 years ago | 0

| accepted

Answered
how to compare string array with the names of structure's fields.
I would use <https://www.mathworks.com/help/matlab/ref/struct2cell.html |struct2cell|> to get a cell array, then used basic MATL...

8 years ago | 1

Answered
how to round 10.5 to 10 ?
fix floor

8 years ago | 0

Answered
How can I find the time difference between each consecutive rows?
Convert to <https://www.mathworks.com/help/matlab/ref/datetime.html |datetime|>. The use <https://www.mathworks.com/help/matlab/...

8 years ago | 0

| accepted

Answered
The resistance r per unit length, as an N-by-N matrix in ohms/km
From the documentation <https://www.mathworks.com/help/physmod/sps/powersys/ref/distributedparameterline.html>: _*"Resistance...

8 years ago | 0

Answered
what is the function that the same as perms however can used n more than 10?
One option would be to use a permutation generator, which does not store all permutations in memory: <https://www.mathworks.c...

8 years ago | 4

Answered
How can I merge a created rectangle with an image?
Use <https://www.mathworks.com/help/matlab/ref/getframe.html |getframe|>: S = getframe(gca); im = S.cdata;

8 years ago | 0

| accepted

Answered
Import .csv Data and assemble structure array
Two tested and working solutions for loading the CSV data and saving it into |mat| files (which is one interpretation of your re...

8 years ago | 2

Answered
Why does output that writing to a file is not the same as its value?
Your format string |'%f\n'| will print exactly one number on each line. If you want multiple number per line then you need to sp...

8 years ago | 1

| accepted

Answered
Checking if all strings exist in row of array
You could use |ismember| and |all|: mat = [5 4 3 2 1; 4 3 2 6 6; 8 5 0 9 6]; str = input('Please enter numbers to test: ...

8 years ago | 0

Answered
How to fix this loop?
Simpler with a numeric vector: >> V = [1,2,3,1,4,6]; >> List = {V(V==1),V(V~=1)}; >> List{1} ans = 1 1 ...

8 years ago | 0

Answered
Operands to the || and && operators must be convertible to logical scalar values.
Explanation: |Q| is not a scalar. You use |Q| in this logical comparison: if (T < Ms) && ((Qscr < Q)&& (Q< Qfcr)) The ou...

8 years ago | 0

Answered
How count NaN values and replace NaNs in a sequence with that number?
No loops, no third-party functions, and works for all MATLAB versions: >> V = [0 0 NaN 0 0 NaN NaN NaN 0 0 0 0 0 NaN]; >...

8 years ago | 1

Answered
How to interpolate at NaN values?
No loops, no third-party functions, and works for all MATLAB versions: >> V = [1 2 3 NaN 4 4.5 5.5 NaN NaN 6 6 7 NaN NaN Na...

8 years ago | 2

| accepted

Answered
Concatenate arrays within a loop,
Easy, given any number of arrays in a cell array |C|. You could use a loop like this, although it is inefficient because the <ht...

8 years ago | 7

| accepted

Answered
How do I create a vector or matrix of variables with undefined variables using matlab or is that even possible?
Get rid of that |x| vector (which is not used for anything, and causes some of your problems), ensure that your matrices have th...

8 years ago | 0

Answered
i want matching 2 matrix index value and if its matched add counter and if incorrect add error value
Loops are not required: cnt = nnz(a==b) err = nnz(a~=b) or if you want to compare all elements to each other, for R20...

8 years ago | 0

Answered
Undefined function or variable 'deltxi'
On this line: Xit = Xito - Xito*(Xis-Xiso)/(1-Xiso) + deltxi; and this line: else deltxi=0; the variable |deltx...

8 years ago | 0

Answered
Find index for mx1 cell with specific string
For comparing a cell array of char vectors and a char vector you have to use |strcmp|, or |strcmpi|, or |strncmp|, etc: idx...

8 years ago | 0

| accepted

Load more