Community Profile

# Stephen Cobeldick

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

Suspensa Vix Via Fit

View details...

Contributions in
View by

Help with printing output
Instead of adding spaces manually you can set the fieldwidth: hours = [13,22,41]; x = [74.52,30.02,22.68]; y = [77.40,36.30,2...

23 hours ago | 0

| accepted

Access all k-th elements of a n-dimensional array, where the k indexes are defined in a (n-1)-dimensional array.
>> S = size(A); >> [R,C,~] = ndgrid(1:S(1),1:S(2),1); >> X = sub2ind(S,R,C,idx); >> B = A(X) B = 1 11 3 13 ...

23 hours ago | 0

For loop using bin2dec conversion
This is MATLAB, you don't need a for loop! Method one: mtimes: >> V = [1,1,0,1,0,0,1,0]; >> N = 2; >> X = pow2(N-1:-1:0)*res...

4 days ago | 0

| accepted

Matrix Generation from Other Matrices
F = @(p)C*A^p*B; M = arrayfun(F,0:n-1,'uni',0); M = cumsum(cat(3,M{:}),3); M = reshape(permute(M,[1,3,2]),[],b); Tested: >>...

4 days ago | 0

| accepted

Replacing NaN's in column of a Matrix
Where M is your matrix: X = isnan(M(:,2)); M(X,2) = 250;

4 days ago | 1

| accepted

For loop goes longer than expected.
"Can you help me what is the cause for this behaviour?" Because that is the indexing that you used. You defined the loop itera...

5 days ago | 0

| accepted

Average of the nine surrounding cells
Use conv2 to calculate the averages, e.g.: out = matrix2.*conv2(matrix1,ones(3,3),'same')/9;

5 days ago | 1

| accepted

How to separate an array into 3
>> A = [11,22,33,44,55,66,77,88,99]; >> B = A(1:2:end-1) B = 11 33 55 77 >> C = A(2:2:end-1) C = 22 44 66 88...

5 days ago | 1

modify the matrix, rearrangement of elements
>> a = [2,4,7,11;7,9,5,54;2,5,7,9;12,41,45,21] a = 2 4 7 11 7 9 5 54 2 5 7 ...

6 days ago | 1

How can I create a new cell array from an existing one?
Country = strrep(Country,'"','')

6 days ago | 0

| accepted

Numerical error representing data in Format Long
"I have had a surprise making with this simple multiplication:" Nothing in that result is surprising. "The result must be 8.2e...

6 days ago | 1

| accepted

Is it possible to determine within a function the location of that function?
https://www.mathworks.com/help/matlab/ref/mfilename.html p = mfilename('fullpath') [p,n] = fileparts(p)

7 days ago | 0

How to list files in the directory
https://www.mathworks.com/help/matlab/ref/dir.html D = 'absolute/relative path to where the files are saved'; S = dir(fullfile...

7 days ago | 0

| accepted

Concatenate same fields in multiple structures in a loop using field names
Because all of the structures contain the same fieldnames they should be stored as one non-scalar structure: https://www.mathwo...

7 days ago | 0

| accepted

How to generate all combinations of N struct vectors.
It is much simpler when those structures are stored in one cell array, e.g.: C{1}(1).a = 5; C{1}(2).a = 9; C{2}(1).b = 2; C{...

7 days ago | 0

Call to function with multiple outputs
[~,y2] = f(x) https://www.mathworks.com/help/matlab/matlab_prog/ignore-function-outputs.html

8 days ago | 0

| accepted

Saving previous values in a function to use them within it
https://www.mathworks.com/help/matlab/ref/persistent.html

8 days ago | 0

| accepted

Sort Data by Second Column
Use sortrows, e.g. where M is your matrix: M = sortrows(M,2); If you really want to use sort, then of course you will need to ...

8 days ago | 0

| accepted

how to plot a vector
"what's wrong with my code?" you preallocate a variable named Vho which you never use again. inside the loop you allocate to a...

10 days ago | 1

| accepted

Error : Undefined variable
You incorrectly transcribed the error message: the actual character shown is lower-case L, i.e. l, not a 1 like you showed. To a...

10 days ago | 0

| accepted

Suppressing ans in a function
To avoid the ans you must use a semi-colon when you call the function: str = encrypt(...); % ^ you need this s...

11 days ago | 0

| accepted

I keep getting two answers for my code
fconvg = int(k*j, x, 0, t) % ^ missing semi-colon This line should probably come after the if-end. Th...

11 days ago | 0

| accepted

Solving linear system 2 equations, 2 unknowns, not A = b*C form
Using a numeric solver or the symbolic toolbox is like using a sledge-hammer to crack open a tiny walnut! It is very simple to ...

11 days ago | 0

Button Colors and Shapes in GUIDE
http://undocumentedmatlab.com/articles/modifying-matlab-look-and-feel https://www.mathworks.com/matlabcentral/fileexchange/4086...

11 days ago | 0

| accepted

How to find the index of first and last nonzero elements in each column?
This works for any array, 2D, 3D, etc., and returns the requested linear indices: >> A = [0,0,0,0;0,0,0,0;1,0,4,8;2,0,5,9;3,1,6...

11 days ago | 1

Create one file from many files
D = 'absolute/relative path to where the files are saved'; N = 25; % number of files C = cell(1,N); for k = 1:N F = full...

11 days ago | 0

Randomly convert exact number of 1 to 0 in binary matrix
>> M = [0,1,0;1,0,1;1,1,1] M = 0 1 0 1 0 1 1 1 1 >> X = find(M); >> M(X(randperm(nu...

11 days ago | 1

need solution asap for my hw about summing each character in student number that we input the data
The MATLAB way: >> str = input('enter your student number here: ','s'); enter your student number here: 20758562 >> num = sum...

12 days ago | 0

error Undefined operator '.*' for input arguments of type 'table'.
The problem is very simple: you are using the wrong type of indexing: instead of () you should be using {} to access the content...

12 days ago | 0