Answered
Split number into parts
If the minutes always has exactly two digits then this can be easily solved using a <https://www.mathworks.com/help/matlab/matla...

8 years ago | 0

| accepted

Answered
Get exact indices of max value in 3D matrix
Use <https://www.mathworks.com/help/matlab/ref/ind2sub.html |ind2sub|>: >> A(:,:,1) = [30 31 32 33 34]; >> A(:,:,2) = [2...

8 years ago | 6

| accepted

Answered
Swapping numbers of two arrays when one is greater than the other
This is MATLAB, so loops and |if|'s are not required: >> Length = [1;5;7]; >> Width = [3;6;4]; >> tmp = sort([Length...

8 years ago | 0

Answered
Convert large cell array to double
_"But when I want convert large model with degree and order for example 2200 (about 2 500 000 lines), code crashed on the third ...

8 years ago | 0

| accepted

Answered
write char array and num to textfile using fprintf
>> a = ['ab';'cd']; >> b = [1;2]; >> c = [cellstr(a),num2cell(b)].'; >> fprintf('%s; %f\n',c{:}) ab; 1.000000 c...

8 years ago | 0

| accepted

Answered
Combining duplicate entries in a data array
Use <https://www.mathworks.com/help/matlab/ref/accumarray.html |accumarray|>: >> x = [0.1, 5, 5, 5, 14.5, 16, 16, 21]; >...

8 years ago | 2

| accepted

Answered
How to extract data from table variable names?
>> C = {'Rectum (4)(Volume: 57.77)','Bladder (5)(Volume: 139.40)'}; >> str2double(regexp(C,'\d+(\.\d+)?(?=\)$)','once','mat...

8 years ago | 0

Answered
How to convert string to number and process underscores? (e.g. '57_77_' to 57.77)
Faster and more efficient than using |str2num| (which hides a slow |eval| call inside) is to simply use the low-level function <...

8 years ago | 1

| accepted

Answered
I keep getting "Undefined operator '*' for input arguments of type 'cell' " when I run this code.
<https://www.mathworks.com/help/matlab/ref/inputdlg.html |inputdlg|> returns a cell array of character vectors, which as the err...

8 years ago | 0

Answered
Help to improve runtime of 3 dimensional matrix
Your code is hugely inefficient because you expand the output array on each iteration. Read this to know more about why that is ...

8 years ago | 1

| accepted

Answered
Why is ga optimization ridiculously slow to solve a problem ?
_"Therefore, in my mind, ga should look up for the minimal value by trying to set the variable with 10 11 12 13 14 15 16 only."_...

8 years ago | 2

| accepted

Answered
help debugging my script?
You wrote a |while| condition that will never be true. Have a look at this line: while n <= n-2 For what values of |n| c...

8 years ago | 0

| accepted

Answered
How to check the condition of both &(and), |(OR) operation in a single line ?
Always use |all| or |any| when using arrays of values with |if|, e.g.: any(-35==Vx(1,1:3)) && any(0==Vy(1,1:3))

8 years ago | 1

| accepted

Answered
how to save every iteration into workspace
Use <https://www.mathworks.com/help/matlab/ref/fullfile.html |fullfile|> rather than string concatenation. To store the imported...

8 years ago | 1

| accepted

Answered
I have a dicom file of size 256*256*3. However, when I read this file using dicomread command in matlab the size of the dicom file is 256*256? How to fix this ?
According to the <https://www.mathworks.com/help/images/ref/dicomread.html |dicomread|> documentation _"For single-frame graysca...

8 years ago | 0

| accepted

Answered
How do I initialize an array of unknown dimension?
_"But how do I do that since I do not know what is the size going to be."_ You have several main choices: * preallocate an...

8 years ago | 3

| accepted

Answered
how to read and stack the details in columns from a cell array?
After the loop: M = cell2mat(cellfun(@(m)m(:),I(:).','uni',0))

8 years ago | 0

| accepted

Answered
How to direct the variable in the genetic algorithm function to workspace function?
You need to parameterize the objective function, which can be achieved either using an anonymous function or nested functions: ...

8 years ago | 0

| accepted

Answered
How to zoom out / shrink the matrix to the desired matrix
You can use <https://www.mathworks.com/help/matlab/ref/interp2.html |interp2|>, e.g.: M = your 8x8 matrix V = linspace(1...

8 years ago | 0

| accepted

Answered
TEXTREAD File not found error
if 2==exist(Datafile, 'file')

8 years ago | 0

| accepted

Answered
When solving for x in Ax=b, why is A\b faster that A^-1 * b?
Because |\| is just one efficient command, rather than the two slow commands required with |inv|. The <https://www.mathworks....

8 years ago | 1

| accepted

Answered
i am in trouble
new = reshape(img(i-1:i+1,j-1:j+1,:),1,[]); new(5) = []

8 years ago | 0

Answered
write a computer program that finds all the isolated primes between 50 and 100. Do not use MATLAB's built in function isprime.
While <https://www.mathworks.com/help/matlab/ref/if.html |if|> does accept vectors for the condition, using vectors often causes...

8 years ago | 0

Answered
function in a script...
Do not supply the function as a string: this syntax is basically deprecated, and is discouraged in the documentation: _"Defining...

8 years ago | 0

| accepted

Answered
How to create a sine wave over given no of samples
smp = 2048; cyc = 2.5; X = linspace(0,cyc*2*pi,smp); Y = sin(X); plot(X,Y) <</matlabcentral/answers/uploaded_fi...

8 years ago | 0

| accepted

Answered
How do I put a condition into a specific column for matlab?
This should get you started, just play around with the logical conditions and character concatenation until you get what you wan...

8 years ago | 0

| accepted

Answered
Output argument "dydt" (and maybe others) not assigned during call
The problem has nothing to do with the ODE solver, it is because of how you defined your function like this: function dydt ...

8 years ago | 0

| accepted

Answered
Multiple lines in one graph
Here is one solution using NaN's to mask out parts of the lines, and plotting them for each thickness. For this to work it is al...

8 years ago | 0

| accepted

Answered
How to store a number with its leading zeros?
To define |x| as a character vector: x = '012345678' See: <https://www.mathworks.com/help/matlab/characters-and-strings....

8 years ago | 0

Answered
Convert 3D matrix (X by Y by Z) into 2D (3 by (X+Y+Z))
A = [Xgrid(:),Ygrid(:),Zgrid(:)].'

8 years ago | 0

| accepted

Load more