Community Profile

# Stephen Cobeldick

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

Suspensa Vix Via Fit

View details...

Contributions in
View by

For loop for unequal increment
You are confusing two different ways of defining filenames. Currently you use dir to get the actual filenames from the OS, but t...

24 hours ago | 0

How to split a string of digits into groups of three from right-to-left using only regular expressions?
With one regexp call (uses lookaround assertion): >> str = '12345678'; >> regexp('123456', '(^\d{1,2}(?=(\d{3})*\$)|\d{3})','ma...

1 day ago | 1

Index 3D Array with 2D logical array
P = size(A,3); F = @(b,s)repmat(b,1,1,P)&reshape(ismember(1:P,s),1,1,P); % requires >=R2016b A(F(B,[1,2,3])) = A(F(B,[5,6,7]))...

1 day ago | 0

Finding three columns in one variable in another variable
I tried a simple vectorized solution of permute and sum of squares approach, but ran into "out of memory" issues: >> C = dlmrea...

1 day ago | 1

| accepted

How to extract numeric values from char
>> C = {'{"name":"rect","x":101,"y":30,"width":239,"height":244}'; '{"name":"rect","x":503,"y":88,"width":124,"height":165...

1 day ago | 1

| accepted

How to move values of matrix for 1 out of two rows?
>> M = [1,0,5,0;2,0,6,0;3,0,7,0;4,0,8,0] M = 1 0 5 0 2 0 6 0 3 0 7 0 4 0 8 0 >> M(2:2:...

2 days ago | 0

Creating RGB images with MATLAB
% 1. green at the left image border to black at the right border % 2. blue at the left image border to white at the right borde...

2 days ago | 1

| accepted

How can I fopen files in different directory
Do NOT follow advice of just adding more directories to the Search Path: this just pointlessly slows MATLAB down (MATLAB has to ...

2 days ago | 0

| accepted

How to use a vector to index another vector?
That function output is rather fragile, as there is no way to distinguish zeros (data) from zeros (place holders). This could ea...

3 days ago | 0

Shor Algorithm for prime factoring

3 days ago | 1

| accepted

find the nearest values
You were almost there, you just need to use the second output from min to make it easier: >> A = rand(1,2) A = 0.39011 0...

3 days ago | 1

| accepted

Selecting min value per row unless min value is repeated in another row.
Set the duplicate values to Inf/NaN, take the minimum of each row, then remove the Inf/NaN values: >> A = [1,2;1,3;2,3;5,6;3,7;...

3 days ago | 0

| accepted

Using a string shortcut for nested structure
For accessing a field of one specific structure (which can be nested) you should use dynamic fieldnames: https://www.mathworks....

4 days ago | 1

| accepted

How to save the result of stlwrite to a specific directory chosen by the user
TR = ... [F,P] = uiputfile('*.stl'); stlwrite(TR,fullfile(P,F))

4 days ago | 0

While loop not starting
Lets have a look at the first y value: >> f = @(x) 4*x^2 - 3; >> x(1) = 0.5; >> y(1) = f(x(1)) y = -2 And now look at your ...

5 days ago | 1

| accepted

FSOLVE requires all values returned by functions to be of data type double
The function handle definition is incorrect: @(B)@ourfun What you defined is an anonymous function which when called accepts o...

5 days ago | 1

| accepted

Indexing with two matrices
>> [C,~] = find(bsxfun(@eq,permute(A,[1,3,2]),permute(B,[3,1,2]))); >> C = reshape(C,size(B)) C = 2 1 2 4 3 4

5 days ago | 0

How to search through entirety of one field of a structure
The general solution is to use comma-separated lists: https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.h...

6 days ago | 0

Importing data with unequal number of column
This is very simple and efficient using fscanf: [fid,msg] = fopen('Data.txt','rt'); assert(fid>=3,msg) mat = fscanf(fid,'%f',...

7 days ago | 1

| accepted

Extracting second number after comma within parenthesis
Simply match all text from the comma to the whitespace: >> str = 'Toc(Clock Data Ref Time) : 0x91E6 (37350,5.976000e+005 s...

7 days ago | 0

Using strcmp with multiple inputs
You could use strfind or a regular expression to help you, e.g.: >> ixc = cellfun(@ischar,rw(:,3)); >> ixc(ixc) = ~cellfun('is...

7 days ago | 0

| accepted

declaring a new table
For historic and compatibility reasons if the variable does not exist before the dot-indexing allocates to it, then MATLAB will ...

7 days ago | 0

How to convert these char values to datetime format?
The error is caused by the milliseconds in start string: either you need to remove them from the input string, or specify them i...

8 days ago | 1

| accepted

Trying to modify a vector by removing alternate elements
There is no point in defining n when it always has exactly the same value as the loop iteration variable i. Get rid of one of th...

8 days ago | 1

| accepted

How to solve pre-allocating array?
Using numbered variables is a sign that you are doing something wrong. Accessing numbered variables is one way that beginners f...

9 days ago | 1

| accepted

How to pass a matrix (m, 1) to (m / 2.2)
>> reshape(V,2,[]).' ans = 1 2 3 4 5 6

11 days ago | 1

| accepted

How to generate 1 cross zero structure in Matlab??
B = reshape(A,1,0)

11 days ago | 1

| accepted

How to call a created function in a different function
Download my FEX submission num2ordinal and use it together with func2str: function out = myNewFunc(fun) val = str2double(regex...

13 days ago | 0

| accepted

flip an array with the use of vectors
"Any suggestions?" Use indexing (which in MATLAB starts from 1): >> a = [1,7,5,9,3,2,4,1] a = 1 7 5 9 3 2 4 ...

15 days ago | 0

| accepted