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...

7 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...

7 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...

7 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 ...

7 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); ...

7 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 ...

7 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...

7 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...

7 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...

7 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 ...

7 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 ...

7 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 ...

7 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. >>...

7 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...

7 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...

7 years ago | 0

| accepted

Answered
creating a structure in for loop
Use the syntax shown in the MATLAB documentation: >> a = {'see','why'}; >> KPI = {'L','L2','L3'}; >> S.(a{1}).(KPI{1}) = 5; ...

7 years ago | 3

| accepted

Answered
Distribute colormap matrice for n values where colormap name comes from GUI
"I don't know why it does not work as I intend, is it possible that this way (e.g. cmap = hsv (n); ) does only work for the pred...

7 years ago | 0

| accepted

Answered
loop over a cell and combine cell columns into one column
Where C is your cell array: >> C(:,2) = cellfun(@cell2mat,num2cell(C(:,3:end),2),'uni',0) C = [1x7 double] [1x6 doubl...

7 years ago | 1

| accepted

Answered
How to change multiple line text into vector (string)
"..or to remove every "enter" from a text to create one line text." That is easy with fileread and regexprep: >> str = filerea...

7 years ago | 1

| accepted

Answered
Is there an alternative way to perform the following matrix transformation?
>> N = 3; >> [R,C] = size(A); % specify R to change the number of rows of A used. >> X = hankel(1:N,N:R); >> B = reshape(A(X,...

7 years ago | 0

Answered
Unexpected behaviour from ishandle()
On MATLAB versions prior to R2016b zero is the handle to the graphics root (i.e. the parent of all graphics figures): https://w...

7 years ago | 0

| accepted

Answered
Find set of values that are unique to the values in another column
>> M = [2,3;2,6;2,8;4,5;5,9;5,39;5,6] M = 2 3 2 6 2 8 4 5 5 9 5 39 5 6 ...

7 years ago | 1

Answered
importing excel file to matlab without losing date format?
Simpler: >> T = readtable('test.xlsx','ReadVariableNames',false); >> T.Properties.VariableNames = {'ymd','HMS','data'}; >> D ...

7 years ago | 0

Answered
How do I get the date out of a filename using regexp?
In one line without intermediate indices or double vector: >> str = 'xxx_2014_06_03_00_00_01'; >> dtm = datetime(regexp(str,'(...

7 years ago | 0

Answered
count string in a cell array
>> S = '945'; >> C = {'1234', '9456', '9457'}; >> nnz(~cellfun(@isempty,strfind(C,S))) ans = 2

7 years ago | 0

Answered
How do I call a function handle with an vector - rather than a list of arguments
Easy: first define a cell array: C = {a1Init, wG1, x1,a2, wG2, x2, c, x}; and then use a comma-separated list: fitFunctionHan...

7 years ago | 1

Answered
Load data from mat files to a matrix
N = 50; C = cell(1,N); for k = 1:N F = sprintf('%d.mat',k); S = load(F); C{k} = S.Data(:,3); end M = [C{:}] ...

7 years ago | 0

Answered
how to insert a value into the array in a consistent manner.
>> A = ones(3,1); >> A(end+1) = 0; >> A([2:end,1]) = A A = 0 1 1 1

7 years ago | 0

| accepted

Answered
Code overwrites results in for loop. Cannot figure out how to index.
Either alpha_beta(k,1) = first_data(1); alpha_beta(k,2) = first_data(3); or alpha_beta(k,1:2) = first_data([1,3]); And reme...

7 years ago | 0

| accepted

Answered
Index exceeds the number of array elements (35).
You have repeatedly used syntax with an = sign, which assigns those values to some variables, e.g: xlabel=('estimated time--->'...

7 years ago | 2

Load more