Community Profile

# Stephen Cobeldick

##### Last seen: Today
6,397 total contributions since 2014

Suspensa Vix Via Fit

#### Stephen Cobeldick's Badges

View details...

Contributions in
View by

how to center a string
str = '23'; num = 9; tmp = (num-numel(str))/2; out = sprintf('%*s%*s',fix(tmp)+numel(str),str,ceil(tmp),'')

1 day ago | 0

"My question is why the term 1.0e-05 * appearing?" Because you are displaying the values in the command window using long forma...

3 days ago | 0

| accepted

How to filter a structure array based on a numeric value from a field?
You will need to concatenate the comma-separated list into one numeric array, e.g.: trips([trips.dir_id] == 1); % ^ ...

3 days ago | 0

| accepted

how would I add several matrices into one? (assembling global stiffness matrix for FEA)
This is easy when you store all of the matrices in one cell array, then you just need a simple for loop: >> C = {[1,1;1,1],[1,1...

3 days ago | 1

| accepted

Adding numbers in array in a specific order
>> [~,~,X] = unique(a); >> d = accumarray(X(:),b(:)) d = 81 122 245 985 2663

3 days ago | 0

| accepted

How can I sample n elements from each column of a matrix?
>> X = sub2ind([4,5],randi(4,2,5),[1:5;1:5]); >> B = A(X) B = 3 8 9 13 20 3 7 10 15 20

3 days ago | 0

How to call a function
Make these changes: clear,clc,close all % <-------- DELETE THIS AWFUL ANTIPATTERN LINE OF EVIL function [C1, C2, C3, C4, C5, s...

4 days ago | 0

| accepted

Passing extra output arguments from ode
"In summary my question is, how do I obtain f for the same time instants at which x is obtained." Using a persistent variable o...

4 days ago | 0

| accepted

why matlab always show my equation as matrix dimension
Most likely you need to follow the advice given in the error message and use array operations, e.g.: y = (668.061./x).*(-39-exp...

5 days ago | 0

readcell command doesn't work anymore!
This only reads one cell: "Range",'B3:B3' There is nothing in your code that reads "all non empty cells in col B starting from...

5 days ago | 0

| accepted

Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
function Weight= SGD_method(...) alpha=0.9; N=4; end % <--------- DELETE THIS LINE! for k=1:N ...

6 days ago | 0

Dynamic regular expression replacement: token number
It can be done with one dynamic replacement expression: >> str = '(1st MT)_fjezhfjksdhf_(2nd MT)'; >> rgx = 'MT'; >> out = re...

6 days ago | 0

how to do the matrix computation
>> M = c(1,2:end).' + c(2:end,1).' - c(2:end,2:end); % requires MATLAB >= R2016b >> M = triu(M,1) + triu(M,1).' M = 0 1...

8 days ago | 1

| accepted

Define a series of matrices
Using numbered variables is not going to be neat or efficient. The MATLAB approach would be to use one array, e.g.: sigma = -5:...

8 days ago | 0

| accepted

How to interpolate column and row?
Use interp2, e.g.: >> Y = [1.0101,1.25,2,5,10,25,50,100]; >> G = [3,2.8,2.6,2.4,2.2,2,1.8,1.6,1.4,1.2,1,0.8,0.6,0.4,0.2,0,-0.2...

8 days ago | 1

| accepted

'run' command with input argument - MATLAB 2018a
run does not work with functions, it only works with scripts: https://www.mathworks.com/help/matlab/matlab_prog/scripts-and-fun...

8 days ago | 0

| accepted

I have 16 GB of RAM, why can't I load a 3.5 GB file?
This line has very inefficient use of memory, and is likely the cause of the error: video=uint16(zeros(zeilen,spalten,frames));...

9 days ago | 2

| accepted

Moving large matrix from function workspace to base workspace?
The correct function to use is assignin, not evalin: assignin('base','data',data) Probably even better would be to just use th...

11 days ago | 3

| accepted

Constructing a circular type of matrix
For MATLAB versions >=R2016b: >> M = max((1:4).',1:5) M = 1 2 3 4 5 2 2 3 4 5 3 3 3 4 5 ...

12 days ago | 0

| accepted

find missing element between two matrix
>> A = [1,2;3,6;3,5;1,4;4,6;2,7;1,6;6,5;2,3;6,7;3,4]; >> B = [1,2;1,6;2,3;3,4;4,6]; >> R = setdiff(A,B,'rows') R = 1 4 ...

12 days ago | 0

| accepted

New line after fprintf
Add a newline at the end of the fprintf format string: fprintf('....\n',D) % ^^ newline!

12 days ago | 1

| accepted

fprintf cell array of two classes
No need for complex strings, ugly loops, or slow arrayfun, you just need one simple fprintf call:: >> A = ['USA' ; 'CAN' ; 'FRA...

12 days ago | 2

store workspace file in variables using a for loop
Your approach is entirely the wrong way around. Putting meta-data (e.g. pseudo-indices, subject IDs, parameter values, etc.) int...

12 days ago | 0

| accepted

How to get common sub string in cell array string?
1- Download and unzip John D'Errico's FEX submission https://www.mathworks.com/matlabcentral/fileexchange/27460-string-subseque...

12 days ago | 1

| accepted

# 1:end
"explain please" Explanation "why this fill whole matrix" g(r(1:end),c(1:end))=1 The MATLAB documentation explains "There is...

13 days ago | 0

I have a 2 by 26 matrix, how do i randomly select one of the rows and extract them?
idr = randi(26,1,1); row = shiptext(idr,:)

14 days ago | 0

| accepted

Periodically save matrixes (or workspace) within PARFOR loop

15 days ago | 0

Why doesn't cd command work on parametric directory names ?
"How can I resolve it ?" Use function syntax (not command syntax): cd(sub) https://www.mathworks.com/help/matlab/matlab_prog/...

16 days ago | 1

Stop the Inf numbers
You used the wrong operator: mrdivide / solves a system of linear equations. You need to learn the differrences between matrix ...

17 days ago | 1