Community Profile

photo

Stephen Cobeldick


5,606 total contributions since 2014

Suspensa Vix Via Fit

Stephen Cobeldick's Badges

  • Master
  • 36 Month Streak
  • Thankful Level 4
  • Revival Level 2
  • Knowledgeable Level 4
  • First Answer

View details...

Contributions in
View by

Answered
How can I extract a variable that is calculated inside an ode function and pass it as an input to the event function?
The simplest solution is to use nested functions: https://www.mathworks.com/help/matlab/matlab_prog/nested-functions.html Basi...

4 hours ago | 0

Answered
How to create the array [1, 2,2 ,3, 3, 3, 4,4 4, 4]?
>> V = 1:10; >> floor(sqrt(2*V)+1/2) ans = 1 2 2 3 3 3 4 4 4 4

9 hours ago | 0

| accepted

Answered
Incorrect use of '=' operator. To assign a value to a variable, use '='. To compare values for equality, use '=='.
The actual problem starts on this line: f=@(t,z)[ ... because your code is missing the matching ] Using = was correct. Note ...

10 hours ago | 1

| accepted

Answered
How to extract values from a string.
>> S = 'Delft_2_220_20_4344-5088.csv'; >> V = str2double(regexp(S,'\d+','match')) V = 2 220 20 ...

10 hours ago | 1

| accepted

Answered
How to find line of code that prints ans
Method one The MATLAB editor already identifies (most of) these lines for you! This is one of the many helpful features that t...

10 hours ago | 1

Answered
Problem with my if else command
An IF statement is not appropriate (without a loop). The simple MATLAB way is to use indexing: >> a = 1; >> b = 1; >> x_15 = ...

12 hours ago | 0

| accepted

Answered
Not equal operator not working on matrix size
"Why does == work as expected, but ~= doesn't?" They both work exactly as expected. "Did I make a mistake?" The IF documentat...

13 hours ago | 2

| accepted

Answered
Transform NaN into number
Your original description failed to mention several things, including the size of the numeric vector and also that the numeric v...

1 day ago | 1

Answered
creating a vector from a bin count
R2015a or later: >> M = [0 5; 1 2; 2 1]; >> repelem(M(:,1),M(:,2)).' ans = 0 0 0 0 0 1 1 2 ...

1 day ago | 1

| accepted

Answered
displaying matrix in .txt file (fprintf)
No loop required: mat = [1,1,1,1;0,-49+4i,-49-4i,-52;0,-2417,-2417,-2392;0,-117649-64i,-117649+64i,-117676]; fmt = ' |%.2f%+.2...

1 day ago | 0

Answered
How to create an empty struc with fields of a given struct?
The simplest and most efficient solution to the question posed is to just use indexing, e.g.: >> A(1).x = 1; >> A(1).y = 2; >...

1 day ago | 1

Answered
How do I get a bar chart in the newest version but with the colors from an older version?
"I have not been able to locate a definitive answer to what the default colors are for a bar chart." The bar documentation stat...

1 day ago | 0

| accepted

Answered
Calling a function in MATLAB
To call a function or a script, just write its name with the necessary inputs: my_function(...) Or my_script This works in t...

2 days ago | 0

| accepted

Answered
Undesired behaviour of bsxfun and colon-operator
A robust workaround using ndgrid and arrayfun and exactly the same function: >> [X,Y] = ndgrid(1:3,6:9); >> arrayfun(@(x,y)x+s...

2 days ago | 0

| accepted

Answered
How can I create all possible random combinations of word pairs without having the same values (for example, house - house)?
Pick random rows from X to get the random pairs: >> Tile = {'house', 'core', 'word', 'ask', 'question', 'horse', 'phone', 'eyes...

2 days ago | 0

| accepted

Answered
to print following pattern
Three lines, no loop, and only basic numeric operations used: >> X = 1:9; >> Y = floor((137174210/1111111111)*10.^X); >> fpri...

2 days ago | 3

Answered
automatically filling a matrix
Just use blkdiag and a comma separated list: >> n = 5; >> j = 6; >> C = {-ones(n,1)}; >> M = blkdiag(C{ones(1,j)}) M = -...

3 days ago | 0

| accepted

Answered
combining different csv files from a folder into one matrix
"Is theremaybe a way to list the filenames in the same order, then add them afterwards as the top row to the table?" You could ...

3 days ago | 0

| accepted

Answered
Inserting more rows between already existing rows of a structure
"but I am not sure how to tansfere that onto a structure. " In exactly the same way. All MATLAB arrays use the same indexing co...

3 days ago | 0

Answered
How to use eval and disable the edit box or drop down?
Do NOT use eval for trivial code like this! Much better is to read the documentation on dynamic fieldnames: https://www.mathwo...

3 days ago | 1

| accepted

Answered
How do I extract images from a docx (word) file?
All OpenOffice XML formats (e.g. .docx, .xlsx, etc.) constitute XML files and supporting files zipped together into one file. Yo...

3 days ago | 0

Answered
Generate combinations of Cells that contain text
Simple and efficient with ndgrid and strcat: >> [Cx,Bx,Ax] = ndgrid(1:numel(C),1:numel(B),1:numel(A)); >> D = strcat(A(Ax(:)),...

3 days ago | 0

Answered
Find Borders and their Indices
Simple and efficient using diff and find: >> D = diff([false,A==0,false]); >> B = find(D>0) % begin of run of zeros B = 1...

3 days ago | 1

| accepted

Answered
subtracting a number from string
The most efficient solution by far (and simple too!): >> str = 'subject1_EO'; >> val = sscanf(str,'subject%f') val = 1

3 days ago | 0

Answered
Convert cell to duration array
"Is there an elegant equivalent to "cell2mat" when cell content is "duration"?" Yes, this is really easy with a comma-separated...

3 days ago | 1

| accepted

Answered
i have a problem with use of natsortfiles function and divide my images
It is not clear what you expect this line structtt = cat(1,cellFileNames{:}); to do, but in actual fact it will vertically con...

3 days ago | 1

| accepted

Answered
how can i express the following question in matlab about save command?
Use uiputfile for a more professional user interface, e.g.: [F,P,X] = uiputfile({'*.jpg';'*.png'}); imwrite(A,fullfile(P,F))

4 days ago | 0

Answered
how to loop through subfolders and apply a particular function
A simple function which correctly handles special characters in the pattern and actually calls the nested function recursively: ...

7 days ago | 0

Answered
replacing uiget with pathname and filename
You use dir without any specific name+wildcards, so it will return all contents of that folder (i.e. files and folders). You the...

7 days ago | 1

| accepted

Answered
finding the right values for a vector
Use mrdivide: >> V = (1:15).'; >> a = pi; >> M = a/V M = 0.0025335 0.0050671 0.0076006 0.0101342 0.0126677 0.0...

7 days ago | 1

Load more