Community Profile

photo

Stephen Cobeldick


4,763 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
Alternatives for using EVAL to access data in multi-layered struct?
One simple solution is to use <https://www.mathworks.com/help/matlab/ref/getfield.html |getfield|> and <https://www.mathworks.co...

4 days ago | 1

| accepted

Answered
even after using fopen, still giving negative fid. how to get a valid fid?
You need to actually pass the filename to |fopen|: fnm = fullfile(matlabroot,'1.txt'); [fid,msg] = fopen(fnm,'r'); as...

4 days ago | 0

Answered
Assess element in struct which filed name contains '.'
You will need to use a <https://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variables.html dynamic field...

5 days ago | 0

| accepted

Answered
sprintf only get the first character in a string array
_"Why does it happen and how I can fix this?"_ Because |[]| is a _concatenation_ operator, not a list operator as some beginn...

5 days ago | 0

| accepted

Answered
How do I rename a variable, as it changes in a Loop
This is easy, as long as there is only *one* variable loaded from each |.mat| file: for k = 1:60 F = sprintf('Data%d...

5 days ago | 1

| accepted

Answered
Hi there! I'm just starting with matlab, so this question may seem a little too easy.
_"Can I return a vector from a function?"_ Of course. _"If yes, what syntax should I use?"_ Nothing special, exactly th...

5 days ago | 0

Answered
converting a decimal number to its binary.
>> N = pi; % example number >> S = num2hex(N) S = 400921fb54442d18 >> X = sscanf(S,'%1x'); >> B = num2cell(dec2bin...

5 days ago | 0

Answered
How to pass a variable from one GUI to other GUI
In GUI1, where |d| is the data that you want to transfer: setappdata(0,'mydata',d); IN GUI2: d = getappdata(0,'myda...

5 days ago | 0

Answered
Unable to read MAT-file E:\my_file.mat: not a binary MAT-file.
_"How can I solve this problem?"_ The so-called |.mat| files at <https://github.com/lokesh1agarwal/SDI> are NOT MATLAB |.mat|...

5 days ago | 0

| accepted

Answered
Sort with respect to identical elements in a column.
>> a = [51,1.5,3.8;52,1.8,9.6;53,2.1,8.8;51,3.5,9.9;54,8.5,10.23;51,1.5,3.8] a = 51 1.5 3.8 52 1.8 9.6 5...

6 days ago | 1

| accepted

Answered
Is there a function that populates a matrix whose minor diagonal are all the same?
Use <https://www.mathworks.com/help/matlab/ref/hankel.html |hankel|>: >> V = [1,7.9,100,18.2,-3.4]; >> hankel(V(1:3),V(3...

6 days ago | 0

| accepted

Answered
Change the value of a matrix element based on the index given in another matrix
*Method one:* |sub2ind|: >> a = zeros(3); >> c = [1,3,2]; >> r = 1:size(a,1); >> a(sub2ind(size(a),r,c)) = 1 a ...

6 days ago | 0

| accepted

Answered
find a same element inside a cell
You could do this in two lines, but here I show it on four lines: >> A = {[1,2,5],[2,3,4],[1,2,4,5],[4,7,9],[1,2,4,5,6,9,10...

6 days ago | 1

Answered
When I run my function I want a row vector not a column
One simple solution is to use subscript indexing (but this will be quite inefficient): function n = num(k) n(1,1) = 1; ...

6 days ago | 0

| accepted

Answered
Why is Movefile creating a folder instead of renaming a file?
When renaming a file using <https://www.mathworks.com/help/matlab/ref/movefile.html |movefile|> you can only specify *one* file ...

6 days ago | 0

| accepted

Answered
Function Call not working properly
You probably want to be using logical indexing rather than |if|: function y = fun(x) y = zeros(size(x)); idx = x>5...

6 days ago | 0

Answered
Write data from for loop into a file
You need to open the file _before_ the loop, print the text _inside_ the loop, and close the file _after_ the loop: [fid,ms...

6 days ago | 0

| accepted

Answered
Changing file names based on their filetype extension
D = 'path to the parent directory where the folders are'; S = dir(fullfile(D,'*')); S = S([S.isdir]); for k = 1:numel...

6 days ago | 0

Answered
How to make a scale-able structure array with variable values
_"Is it possible to put a maths expression in there, and if so how?"_ You could define it as a function: >> S.fun = @(le...

6 days ago | 0

Answered
How could I get my function to produce this?
You will need to use a dynamic fieldname: <https://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variab...

7 days ago | 0

| accepted

Answered
FUN must be a function, a valid character vector expression, or an inline function object. | fzero
You don't need to store the functions in any array, you only need to store the output values: function out = FA(y) out =...

7 days ago | 0

Answered
Getting variables for different files
Just use <https://www.mathworks.com/help/matlab/cell-arrays.html cell arrays>: N = numel(location); A = cell(1,N); B ...

7 days ago | 0

| accepted

Answered
bug in find function
_"bug in find function"_ There is no bug in |find|. You have just discovered that two _different_ floating point numbers are ...

7 days ago | 0

Answered
re-order array structs of arrays
Here is a 1x3 structure with two 1x4 numeric fields: S(1).f1 = 0:3; S(1).f2 = 2:5; S(2).f1 = 1:4; S(2).f2 = 3:6; ...

7 days ago | 0

| accepted

Answered
How to compare elements of two equal size matrices by logical conditionals?
@MARCELA FRAGOZO: simpler and more efficient: C = min(A,B) Try it, and you will see that it does the same as your logic....

7 days ago | 0

Answered
Sorting problem with months in file names, while taking average
Two solutions: 1) Use <https://en.wikipedia.org/wiki/ISO_8601 ISO 8601> dates in the filenames, then they can be sorted using...

7 days ago | 1

| accepted

Answered
Counting up starting from first row of zeros in a matrix, then 1's.
>> a = [1,6,2;7,8,3;4,5,9] % what you want a = 1 6 2 7 8 3 4 5 9 >> m = [0,1,0;1,1,0;0,0,1...

7 days ago | 1

| accepted

Answered
Convert tables to arrays in a for loop
C = {data_1, data_2 ,data_3, data_4,data_5}; D = cellfun(@table2array,C,'uni',0)

7 days ago | 1

| accepted

Answered
Horizontal concatenation of sub-matrix into a bigger matrix based on value of first column
Using <https://www.mathworks.com/help/matlab/ref/unique.html |unique|> and <https://www.mathworks.com/help/matlab/ref/accumarray...

8 days ago | 1

| accepted

Answered
How to copy a structure without a field?
Use <https://www.mathworks.com/help/matlab/ref/rmfield.html |rmfield|>: q = rmfield(p,'field2')

8 days ago | 0

| accepted

Load more