Answered

Dynamically naming new table columns in a loop

"What's the secret?" Very simple: don't use EVAL. It is simpler, much more robust, and much more efficient to add fields using...

Dynamically naming new table columns in a loop

"What's the secret?" Very simple: don't use EVAL. It is simpler, much more robust, and much more efficient to add fields using...

1 month ago | 0

| accepted

Answered

Convert numerical Matrix values into logical Matrix

A = [1,3,4,9,12;2,5,6,9,11;1,4,5,10,12] X = any((1:12)==permute(A,[1,3,2]),3) M = [1:12;+X]

Convert numerical Matrix values into logical Matrix

A = [1,3,4,9,12;2,5,6,9,11;1,4,5,10,12] X = any((1:12)==permute(A,[1,3,2]),3) M = [1:12;+X]

1 month ago | 0

| accepted

Answered

Split cell each 13 characters

The better approach is to use READMATRIX or READTABLE with the fixed-wdith importing option: fnm = 'test.txt'; opt = detectImp...

Split cell each 13 characters

The better approach is to use READMATRIX or READTABLE with the fixed-wdith importing option: fnm = 'test.txt'; opt = detectImp...

1 month ago | 1

| accepted

Answered

How to use 'for' loop to string variable ?

Assuming that each file contains exactly one variable (itself a structure with the same field names): T = ["Battery_Power_280",...

How to use 'for' loop to string variable ?

Assuming that each file contains exactly one variable (itself a structure with the same field names): T = ["Battery_Power_280",...

1 month ago | 0

| accepted

Answered

How to determine if table format value is array or cell?

Summary: you need to use curly braces to refer to the content of a table. Explanation: tables are a container class: they are a...

How to determine if table format value is array or cell?

Summary: you need to use curly braces to refer to the content of a table. Explanation: tables are a container class: they are a...

1 month ago | 0

Answered

How to display a table without it showing "var1"?

Tables are a container class: they contain data of other classes. So it is very important to distinguish between the table itsel...

How to display a table without it showing "var1"?

Tables are a container class: they contain data of other classes. So it is very important to distinguish between the table itsel...

1 month ago | 0

| accepted

Answered

Using strjoin on each row of NxM cell array

C = {'ABC','123','blue';'DEF','456','red';'GHI','789','green'} D = cellfun(@(v)join(v,'_'),num2cell(C,2))

Using strjoin on each row of NxM cell array

C = {'ABC','123','blue';'DEF','456','red';'GHI','789','green'} D = cellfun(@(v)join(v,'_'),num2cell(C,2))

1 month ago | 1

| accepted

Answered

Assigning array values to cell array based on condition

A = [1,1,1,2,2,3,3,3,3]; B = [6,3,7,4,7,13,16,4,1]; C = accumarray(A(:),B(:),[],@(v){v}); C{:} For the second part of your q...

Assigning array values to cell array based on condition

A = [1,1,1,2,2,3,3,3,3]; B = [6,3,7,4,7,13,16,4,1]; C = accumarray(A(:),B(:),[],@(v){v}); C{:} For the second part of your q...

1 month ago | 0

| accepted

Answered

How to load multiple mat files from a folder in a sequence?

S = dir(fullfile(Folder, '*.mat')); for k = 1:numel(S) F = fullfile(Folder,S(k).name); % you need FOLDER here too. d...

How to load multiple mat files from a folder in a sequence?

S = dir(fullfile(Folder, '*.mat')); for k = 1:numel(S) F = fullfile(Folder,S(k).name); % you need FOLDER here too. d...

1 month ago | 0

| accepted

Answered

How I can detection column indexes of string 'rk_accept_metaln' (n=1,2,3,4....)

C = {'X','Y','Z','X_size','Y_size','Z_size','volume','block_tonnage','rk_accept_grade1','rk_accept_metal1','rk_rejected_grade1',...

How I can detection column indexes of string 'rk_accept_metaln' (n=1,2,3,4....)

C = {'X','Y','Z','X_size','Y_size','Z_size','volume','block_tonnage','rk_accept_grade1','rk_accept_metal1','rk_rejected_grade1',...

1 month ago | 0

| accepted

Answered

Compute the mean row cell elements in a cell array.

Where C is your cell array: fun = @(varargin)mean(cat(3,varargin{:}),3); D = cellfun(fun,C(1,:),C(2,:),C(3,:),'uni',0)

Compute the mean row cell elements in a cell array.

Where C is your cell array: fun = @(varargin)mean(cat(3,varargin{:}),3); D = cellfun(fun,C(1,:),C(2,:),C(3,:),'uni',0)

1 month ago | 1

| accepted

Answered

How to index array with an array?

u = [11,12,13;21,22,23;31,32,33] % Access element at row 2, column 1 id = [2,1] ic = num2cell(id); u(ic{:}) https://www.mat...

How to index array with an array?

u = [11,12,13;21,22,23;31,32,33] % Access element at row 2, column 1 id = [2,1] ic = num2cell(id); u(ic{:}) https://www.mat...

1 month ago | 0

| accepted

Answered

How to I call specific values from a 45x1 Matrix?

link_forces = solution([3,5,14,17,25,28]) See: https://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab...

How to I call specific values from a 45x1 Matrix?

link_forces = solution([3,5,14,17,25,28]) See: https://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab...

1 month ago | 0

Answered

Assign a cell data that starts with a regular expression

Always LOAD into an output variable! That will make your code much more reliable, and makes this task easier. Method 1: the sim...

Assign a cell data that starts with a regular expression

Always LOAD into an output variable! That will make your code much more reliable, and makes this task easier. Method 1: the sim...

1 month ago | 0

| accepted

Answered

Removing zeros from matrix

A = [1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,0;1,2,3,4,0,0;1,2,3,0,0,0] Method one: NONZEROS and CELLFUN baz = @(v)v(end); fnh = @(...

Removing zeros from matrix

A = [1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,0;1,2,3,4,0,0;1,2,3,0,0,0] Method one: NONZEROS and CELLFUN baz = @(v)v(end); fnh = @(...

1 month ago | 2

| accepted

Answered

How to distribute elements of a vector to each of output variable?

You can use a comma-separated list: x = [1,2,3,4,5]; c = num2cell(x); [a,b,c,d,e] = c{:} https://www.mathworks.com/help/matl...

How to distribute elements of a vector to each of output variable?

You can use a comma-separated list: x = [1,2,3,4,5]; c = num2cell(x); [a,b,c,d,e] = c{:} https://www.mathworks.com/help/matl...

1 month ago | 0

Answered

Explain why it makes sense that matrix A( :, :, 1) is two-dimensions, while A( :, 1, :) and A(1, :, :) return three dimensions

So far no one has really answered why this makes sense, which is what the original question asked. "My question was more about ...

Explain why it makes sense that matrix A( :, :, 1) is two-dimensions, while A( :, 1, :) and A(1, :, :) return three dimensions

So far no one has really answered why this makes sense, which is what the original question asked. "My question was more about ...

1 month ago | 0

Answered

Create loop to load .mat file and store values to a matrix.

This should get you started. In the absence of any data desription I assumed that withinin each file x and y are scalar. You wil...

Create loop to load .mat file and store values to a matrix.

This should get you started. In the absence of any data desription I assumed that withinin each file x and y are scalar. You wil...

1 month ago | 0

| accepted

Answered

Splitting a table using varagin

"The matlab documentation states that the first term in the bracket after splittaply should be a function such as @max" The SPL...

Splitting a table using varagin

"The matlab documentation states that the first term in the bracket after splittaply should be a function such as @max" The SPL...

2 months ago | 0

| accepted

Answered

Use a ready p-file to operate on matrices

Your approach is complex, obfuscated, and inefficient. Using numbered variables is a sign that you are doing something wrong. R...

Use a ready p-file to operate on matrices

Your approach is complex, obfuscated, and inefficient. Using numbered variables is a sign that you are doing something wrong. R...

2 months ago | 1

| accepted

Answered

Convert time in decimal days into hh:mm:ss format

N = 0.504513888888889; T = days(N); T.Format = 'hh:mm:ss' or D = datetime(N,'ConvertFrom','excel'); T = timeofday(D)

Convert time in decimal days into hh:mm:ss format

N = 0.504513888888889; T = days(N); T.Format = 'hh:mm:ss' or D = datetime(N,'ConvertFrom','excel'); T = timeofday(D)

2 months ago | 0

Answered

Extracting numerator and denominator values from a decimal value

[N,D] = rat(6.52) Multiply both by four if you want to.

Extracting numerator and denominator values from a decimal value

[N,D] = rat(6.52) Multiply both by four if you want to.

2 months ago | 1

| accepted

Answered

Efficiently identifying a set of 1s: follow up question after months later

A simpler, more efficient, much more robust solution: a = [1,1,1,-1,0,0,0,0,1,1,-1,0,0,1,1,1,1,-1,0,0]; d = diff([false,a==1,f...

Efficiently identifying a set of 1s: follow up question after months later

A simpler, more efficient, much more robust solution: a = [1,1,1,-1,0,0,0,0,1,1,-1,0,0,1,1,1,1,-1,0,0]; d = diff([false,a==1,f...

2 months ago | 0

| accepted

Answered

Any efficient way to identify a set of 1s in a big array?

A simple, efficient, robust solution: a = [1,1,1,-1,0,0,0,0,1,1,-1,0,0,1,1,1,1,-1,0,0]; d = diff([false,a==1,false]); s = fin...

Any efficient way to identify a set of 1s in a big array?

A simple, efficient, robust solution: a = [1,1,1,-1,0,0,0,0,1,1,-1,0,0,1,1,1,1,-1,0,0]; d = diff([false,a==1,false]); s = fin...

2 months ago | 0

| accepted

Answered

Problem with datetime in German

There does seem to be a problem with DATETIME handling the period characters (below). Workaround: replace/remove the period cha...

Problem with datetime in German

There does seem to be a problem with DATETIME handling the period characters (below). Workaround: replace/remove the period cha...

2 months ago | 0

| accepted

Answered

Storing many digits using readtable

Any advice that "you are going to need to read the file as text" is incorrect. It is much better to import and store numeric da...

Storing many digits using readtable

Any advice that "you are going to need to read the file as text" is incorrect. It is much better to import and store numeric da...

2 months ago | 0

| accepted

Answered

How to see if characters are present in a string array.

Assuming that all string elements contain exactly the same number of characters, then you can do this easily with basci logical ...

How to see if characters are present in a string array.

Assuming that all string elements contain exactly the same number of characters, then you can do this easily with basci logical ...

2 months ago | 0

| accepted

Answered

Subtracting Matrices in Special way

If the A values are copied first then only two ISMEMBER are required (simpler, more efficient), nor any resizing or changing of ...

Subtracting Matrices in Special way

If the A values are copied first then only two ISMEMBER are required (simpler, more efficient), nor any resizing or changing of ...

2 months ago | 1

Answered

How do I get values of a certain parameter in a multi-dimensional matrix?

a(~Ind) = NaN

How do I get values of a certain parameter in a multi-dimensional matrix?

a(~Ind) = NaN

2 months ago | 0

| accepted

Answered

Display file names from current directory if more than n characters

n = 5; P = 'absolute or relative path to where the files are saved'; S = dir(fullfile(P,'*.*')); C = {S(~[S.isdir]).name}; % ...

Display file names from current directory if more than n characters

n = 5; P = 'absolute or relative path to where the files are saved'; S = dir(fullfile(P,'*.*')); C = {S(~[S.isdir]).name}; % ...

2 months ago | 0

| accepted