Community Profile

# Stephen Cobeldick

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

Suspensa Vix Via Fit

View details...

Contributions in
View by

How to save cell array of workspace vars into mat?
save('test.mat', vars{:}) How it works: https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html https://...

23 hours ago | 1

| accepted

Simple Matrix Reduction Question. Ones and Zeros.
Simpler: >> [B,~] = find(A.') B = 4 1 2 3

2 days ago | 1

How do I match nested parenthesis (brackets, or braces) with dynamic regular expressions?
This matches the outer-most matched pair of parentheses: >> str = 'asdf (( dwer e: ( asdedsdskek))::)asd fg ( qwe 4 dfy5 57) q3...

3 days ago | 1

| accepted

Converting txt file string to matrix.
>> str = '{co-ordinates 1.5 2.5 4.8 weighting 11.7}{co-ordinates 2.5 2.8 1.7 weighting 21.4}{co-ordinates 1.5 2.5 4.8 weig...

4 days ago | 0

| accepted

I am trying to run this script, but it only returns the last part of the switch- the otherwise part, please help...
Your switch condition will not work as you expect. If you want to use logical comparisons for the case values, then you will nee...

4 days ago | 0

Calling a nested function from a dynamic regular expression throws an error
The best and most general workaround I have found so far is to call regexp from a local function, with function handles to the n...

4 days ago | 0

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

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

8 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); % ^ ...

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

9 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

9 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

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

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

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

11 days ago | 0

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

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

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

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

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

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

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

14 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));...

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

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

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

18 days ago | 0

| accepted

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

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

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

18 days ago | 0

| accepted