Community Profile

# Stephen Cobeldick

3,718 total contributions since 2014

Suspensa Vix Via Fit

View details...

Contributions in
View by

Too many files open error yet I am closing files
_"...you will see that after I complete reading each file I close the file using fclose(fID)."_ Nope. You actually only close...

6 hours ago | 0

| accepted

What is the difference between mean(A,'omitnan') and nanmean(A) ?
There is no practical difference for your vector. Personally I would use |mean|, because |nanmean| is part of the Statistics ...

7 hours ago | 1

| accepted

There's an error using input function in my computer , how do I solve it?
The error message is telling you that you have a file named |input|: have a look at the second line of the error message: what d...

9 hours ago | 0

How can I retrieve an element from this array of functions, as a matlabFunction?
Use a cell array to store function handles: C{1} = @(t,y) 10*(y(2)-y(1)); C{2} = @(t,y) y(1)*(28-y(1))-y(2); C{3} = @(t,...

10 hours ago | 1

| accepted

parfor is slower than for
_"I don't see a reason why parfor should be slower than for."_ I don't see a reason why |parfor| should be faster than |for|....

13 hours ago | 0

| accepted

Executing eval in function handle ?
This is a classic example of how the decision to use |eval| to access variables just makes code more complex and introduces more...

14 hours ago | 2

| accepted

I have a cell array of size 1x934 and each cell has 160x160x96 double. I want to make a cell array of 1xn (n i think it is 89664) where each cell has 160x160
*Method one: concatenate into one numeric array, then split.* This will not work of you do not have enough memory for the comple...

16 hours ago | 0

Create a loop with string
Using _command syntax_ with <https://www.mathworks.com/help/matlab/ref/load.html |load|> is one of the main bugs in the code: as...

18 hours ago | 0

Submitted

ColorBrewer: Attractive and Distinctive Colormaps
The complete palette of ColorBrewer colormaps. Simple selection by scheme name and map length.

How to display averages in new array?
This is easy in just a few lines. B = [... 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000...

1 day ago | 0

How do I format a .txt file I've created?
%15:9e is not a valid format string. Perhaps you meant to write a decimal point: %15.9e

1 day ago | 0

| accepted

Trying to do repeat math on multiple variables...
David Fletcher already showed the best way of doing this, which is to use MATLAB efficiently with one numeric array. If you real...

2 days ago | 0

Working with inputs in functions
See these for examples of how to use |str2func|: <https://www.mathworks.com/matlabcentral/answers/337479-how-to-multiply-two-...

2 days ago | 0

How can I show variable index in a for loop?
_"I have 100 matrices, name x1, x2, ..., x100. I want to do the below process for all 100 variables using a "for loop""_ Acce...

4 days ago | 0

| accepted

Divide a matrix with an array along a specific dimension
Once you make the sizes compatible you can do this using standard methods without any loop. Use |permute| or |reshape| to get th...

4 days ago | 0

| accepted

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...

4 days ago | 0

| accepted

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...

5 days ago | 0

| accepted

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...

5 days ago | 0

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 ...

5 days ago | 0

| accepted

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...

5 days ago | 0

| accepted

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]; >...

6 days ago | 1

| accepted

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...

6 days ago | 0

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 <...

6 days ago | 1

| accepted

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...

6 days ago | 0

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 ...

6 days ago | 1

| accepted

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."_...

7 days ago | 2

| accepted

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...

7 days ago | 0

| accepted

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))

7 days ago | 1

| accepted