Answered
How to access object loaded into a struct when object variable name (as saved) is unknown
"I have tried every variation of indexing I can think of..." Indexing is entirely independent from fieldnames, so indexing like...

6 years ago | 1

| accepted

Answered
How can i append cell arrays
C{2}{3} = 45

6 years ago | 0

| accepted

Answered
Collapsing nested cell array values into simple numerical array
"I have used regexp to find some numbers in each element of a cell array." If the regular expression only needs to match once, ...

6 years ago | 0

| accepted

Answered
I really need help with fprintf'ing a string, having it alternate with commas and parentheses.
[~,idx] = ismember(coords,xy.','rows'); % Better: obtain these indices from your function! mat = [idx,coords].'; % should have ...

6 years ago | 0

| accepted

Answered
Values in cell array keep getting overwritten
Much simpler and much more robust: D = 'path to the main directory'; S = dir(fullfile(D,'img*')); for k = 1:numel(S) F =...

6 years ago | 1

| accepted

Answered
2D Convex Hull: I can't think of a 'criteria' to filter out the 'wrong' points, please help!
"I can't think of a 'criteria' to filter out the 'wrong' points." The obvious criteria to pick is in the name convex hull: why ...

6 years ago | 0

Answered
Concatenate I x J*2 x K matrix in I*J x 2 x K matrix
Use reshape and permute, e.g. for two columns: >> A = randi(9,8,4,6); % fake data >> A(:,:,1) ans = 9 1 4 6 7 ...

6 years ago | 0

| accepted

Answered
How to use spacing around operator?
This is explained in the MATLAB documentation: https://www.mathworks.com/help/matlab/matlab_prog/case-and-space-sensitivity.htm...

6 years ago | 0

Answered
Finding maximum number location in a matrix
"Is there a reason why this line is wrong?" Yes, because you nested max inside find. Take a look at the output of max: what is ...

6 years ago | 0

| accepted

Answered
Vectorized implementation for using a vector as an index for matrices
Use sub2ind like this: >> m = 7; >> V = randi([1,10],1,m) V = 9 10 2 10 7 1 3 >> A = zeros(m,10)...

6 years ago | 0

| accepted

Answered
saving multiple .mat files with the same name from a script
"Is there any way it could be save as data1.mat, data2.mat ......data20.mat (if i run the script 20 times)..." You could downlo...

6 years ago | 0

Answered
If I have a logical vector created by ISDIR attribute of DIR, how to have its order by the date of the last modification of folders???
Simpler and much more robust: S = dir('D:\= BIO-PD ='); S = S([S.isdir] & ~ismember({S.name},{'.','..'})); % folders only, exc...

6 years ago | 1

| accepted

Answered
How to find all letters before a character in a char variable
>> secretMes = [';,.T234h467e#i`12n390@%f&^%o1@45r1%^m]\a131@t2i*/-o+/1n#i*895n#t$5&&h1/!i@$$s#f18945@i2/le#i98s#c`$%o%^n77*f(=i...

6 years ago | 1

Answered
Data Sorting (looking for a range that do not exist in a list of numbers)
>> V = [1,2,3,6,7,8,23,24,25,76,77]; >> X = diff(V)~=1; >> B = V([X,false])+1 % missing range begin values B = 4 9 ...

6 years ago | 0

| accepted

Answered
Random shuffle vector such that all elements fall in new index positions
What you describe is called a derangement. You can download FEX submissions that perform derangements: https://www.mathworks.c...

6 years ago | 0

| accepted

Answered
Need to sort the number in the increasing order using MATLAB script, shown as a sample text file.
You could download my FEX submission natsort: https://www.mathworks.com/matlabcentral/fileexchange/34464-customizable-natural-o...

6 years ago | 0

Answered
loop over subfolders and saving cat parameters
If you only need to loop over subfolders then why are you using three loops? One loop for the subfolders, one loop for the files...

6 years ago | 0

| accepted

Answered
Why [] appears after a function?
According to the function documentation, those square brackets contain any output arguments. Because the square brackets you sho...

6 years ago | 1

| accepted

Answered
Generate an array with random numbers from M to N using the command randi
>> R = [2,5]; >> rng('default'); >> A = randi(R,3,8) A = 5 5 3 5 5 2 5 2 5 4 ...

6 years ago | 0

Answered
Help I keep getting error: [Error using griddedInterpolant The grid vectors must contain unique points]
Your grid data points are not unique (which they must be to perform interpolation): >> U = unique(X(:)); >> C = hist(X(:),U); ...

6 years ago | 0

| accepted

Answered
Extract partial data from vectors in structure
>> S.A = 0:3; >> S.B = 4:9 S = scalar structure containing the fields: A = 0 1 2 3 B = 4 ...

6 years ago | 0

| accepted

Answered
Loading part of a structure in a .mat file
The matfile documentation states "The MAT-file object does not support indexing into... Cells of cell arrays..." This means you...

6 years ago | 0

| accepted

Answered
How to loop through the same operation on multiple variables
"Is there a way to shorten this into a loop?" By far the simplest and most efficient solution is to use a cell array and indexi...

6 years ago | 1

Answered
Creating averages for parts of an array in a for loop
Your definitions of the boundary cases make this a bit tricky, but here is one solution: >> A = randi(9,1,10) A = 3.00 2...

6 years ago | 0

Answered
swapping rows in a matrix
>> X = [1,3]; % rows to swap >> M = randi(9,4,5) M = 6 7 6 2 9 2 3 2 1 1 1 6 9 7 9 4 ...

6 years ago | 4

| accepted

Answered
How can I make diamond shape with a matrix?
Without the image toolbox: >> N = 5; >> V = round((N:-1:1)/(N+1)); >> M = toeplitz(V); >> M = M & rot90(M) M = 0 0 ...

6 years ago | 2

Answered
Error using griddedInterpolant: The grid vectors are not strictly monotonic increasing. please help me!
Your data are scattered, not gridded: https://www.mathworks.com/help/matlab/math/overview-of-interpolation-techniques.html so ...

6 years ago | 1

| accepted

Answered
How do I fill empty Matrix elements with NaNs?
Fake data: >> A.a = rand(4,1); >> A.b = []; >> A.c = rand(7,1); >> A.d = rand(10,1); Then you can simply use structfun. >>...

6 years ago | 0

Answered
Finding the shortest path in a cell array based on given input
Each row of the output cell array is one path: >> C = {[0,1],[1,2],[2,3],[3,4],[0,3],[1,4]}; >> V = [0,4]; >> Z = mainfun(C,V...

6 years ago | 2

| accepted

Answered
How to read table with specific word in name
Much simpler and more robust than your code: D = 'path to the directory where the files are saved'; S = dir(fullfile(D,'*fluxa...

6 years ago | 0

| accepted

Load more