Suspensa Vix Via Fit

Answered

dynamically save a matrix to a structure

Do NOT use eval for trivial code like this. Your approach is slow, complex, inefficient, and not recommended. Rather than mess...

dynamically save a matrix to a structure

Do NOT use eval for trivial code like this. Your approach is slow, complex, inefficient, and not recommended. Rather than mess...

23 hours ago | 0

Answered

Conditionally select from array of struct by membership of a list in struct element

X(1).Members = [1,2]; X(1).Name = 'Group 1'; X(2).Members = [2,3]; X(2).Name = 'Group 2'; F = @(n)arrayfun(@(s)any(s.Members...

Conditionally select from array of struct by membership of a list in struct element

X(1).Members = [1,2]; X(1).Name = 'Group 1'; X(2).Members = [2,3]; X(2).Name = 'Group 2'; F = @(n)arrayfun(@(s)any(s.Members...

2 days ago | 0

| accepted

Answered

Can I somehow improve performance of str2double?

The fastest conversion uses low-level commands, e.g. sprintf and sscanf. Instead of this: C = {'1.2','3.4','5.6'}; V = str2dou...

Can I somehow improve performance of str2double?

The fastest conversion uses low-level commands, e.g. sprintf and sscanf. Instead of this: C = {'1.2','3.4','5.6'}; V = str2dou...

3 days ago | 1

| accepted

Answered

How to sort one array based on the order of a second array?

As far as I can tell, the order of Q is irrelevant. A = ["1a","1b","1c","1d","1e","2a","2b","2c","2d","2e"]; % sorted B = ["A1...

How to sort one array based on the order of a second array?

As far as I can tell, the order of Q is irrelevant. A = ["1a","1b","1c","1d","1e","2a","2b","2c","2d","2e"]; % sorted B = ["A1...

3 days ago | 1

| accepted

Answered

Reshape array such that boundaries remain the same

x = [0, 1, 2, 1, 0]; y = [0, 0.5, 1, 1.5, 2, 1.5, 1, 0.5, 0]; xnew = interp1(x,linspace(1,numel(x),numel(y)))

Reshape array such that boundaries remain the same

x = [0, 1, 2, 1, 0]; y = [0, 0.5, 1, 1.5, 2, 1.5, 1, 0.5, 0]; xnew = interp1(x,linspace(1,numel(x),numel(y)))

3 days ago | 0

| accepted

Answered

Why am I getting "Array indices must be positive integers or logical values" error?

Consider this indexing: x1(i-j+1) What value does it have on the last iteration of the j loop? (hint: zero). i-j+1 % that ind...

Why am I getting "Array indices must be positive integers or logical values" error?

Consider this indexing: x1(i-j+1) What value does it have on the last iteration of the j loop? (hint: zero). i-j+1 % that ind...

3 days ago | 1

| accepted

Answered

Get unknown variable from mat-file

Given only one variable saved in the mat file: tmpC = struct2cell(load(filename)); myVar = tmpC{1}; Do not worry about the t...

Get unknown variable from mat-file

Given only one variable saved in the mat file: tmpC = struct2cell(load(filename)); myVar = tmpC{1}; Do not worry about the t...

3 days ago | 0

| accepted

Answered

Extracting the numbers from file names and listing them in a column

C = {'Rpma26siatBz 9.500000 Bx 0.000000mT WWait 2.000000Sec.Bzat9.5mT83.png',... 'Rpma26siatBz 9.500000 Bx 100.000000mT WW...

Extracting the numbers from file names and listing them in a column

C = {'Rpma26siatBz 9.500000 Bx 0.000000mT WWait 2.000000Sec.Bzat9.5mT83.png',... 'Rpma26siatBz 9.500000 Bx 100.000000mT WW...

4 days ago | 0

| accepted

Answered

sum contents of array in groups of 10

Where V is your 1x3001 vector: M = sum(reshape(V(1:3000),10,[]),1)

sum contents of array in groups of 10

Where V is your 1x3001 vector: M = sum(reshape(V(1:3000),10,[]),1)

4 days ago | 0

| accepted

Answered

How to append for each iteration not using cells?

Replace yield(p) = [yield(p); {helper(k)}]; with yield = [yield; helper(:)];

How to append for each iteration not using cells?

Replace yield(p) = [yield(p); {helper(k)}]; with yield = [yield; helper(:)];

4 days ago | 0

| accepted

Answered

How to solve preallocating speed of a variable?

One simple solution is given here: https://www.mathworks.com/help/matlab/matlab_oop/creating-object-arrays.html "To preallocat...

How to solve preallocating speed of a variable?

One simple solution is given here: https://www.mathworks.com/help/matlab/matlab_oop/creating-object-arrays.html "To preallocat...

4 days ago | 1

| accepted

Answered

Undefined function 'split' for input arguments of type 'char'

The function split was introduced in R2016b, so you will not be able to use it with R2013a. You can probably replace that line ...

Undefined function 'split' for input arguments of type 'char'

The function split was introduced in R2016b, so you will not be able to use it with R2013a. You can probably replace that line ...

4 days ago | 0

Answered

Accessing data from a struct cell

Assuming that your structure is named S, you can loop over it like this: for k = 1:numel(S) plot(S(k).data) % default plot...

Accessing data from a struct cell

Assuming that your structure is named S, you can loop over it like this: for k = 1:numel(S) plot(S(k).data) % default plot...

4 days ago | 0

Answered

Convert cell array to vector

S = load('timestamps.mat'); T = vertcat(S.ans{:}) M = seconds(mean(diff(duration(T,'InputFormat','hh:mm:ss.SSS'))))

Convert cell array to vector

S = load('timestamps.mat'); T = vertcat(S.ans{:}) M = seconds(mean(diff(duration(T,'InputFormat','hh:mm:ss.SSS'))))

5 days ago | 0

| accepted

Answered

Maximum number of repeated values over an array

a = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9]; x = cumsum([true;diff(...

Maximum number of repeated values over an array

a = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9]; x = cumsum([true;diff(...

5 days ago | 1

| accepted

Answered

How to compare letters if they are same

Rather than building maps by hand, I would get Python to do the heavy lifting, e.g.: baz = @(v)char(v(1)); % only need the firs...

How to compare letters if they are same

Rather than building maps by hand, I would get Python to do the heavy lifting, e.g.: baz = @(v)char(v(1)); % only need the firs...

5 days ago | 0

Answered

How to convert time stamp 11:21:17.155 into seconds in MATLAB??

The most efficient solution: a = '11:21:17.155'; b = [60*60,60,1]*sscanf(a,'%f:')

How to convert time stamp 11:21:17.155 into seconds in MATLAB??

The most efficient solution: a = '11:21:17.155'; b = [60*60,60,1]*sscanf(a,'%f:')

6 days ago | 0

Answered

Is it possible to make a loop where the the result is separate from the loop and have the result respectively with the input?

Use a cell array to store the data: p = 'Quantity of product you have bought today: '; n = str2double(input(p,'s')); c = cell...

Is it possible to make a loop where the the result is separate from the loop and have the result respectively with the input?

Use a cell array to store the data: p = 'Quantity of product you have bought today: '; n = str2double(input(p,'s')); c = cell...

6 days ago | 0

| accepted

Answered

"If function" can't distinguish i ~= 1.6.

"This weird thing only happens when i=1.6." Nothing weird happens: you generate binary floating point numbers using two differe...

"If function" can't distinguish i ~= 1.6.

"This weird thing only happens when i=1.6." Nothing weird happens: you generate binary floating point numbers using two differe...

7 days ago | 1

| accepted

Answered

replacing loop with cell of index values

s = 1:100; c{1} = 1; c{2} = 1:5; c{3} = 2:2:10; out = cellfun(@(x)s(x),c,'uni',0); out{:} A well-written (i.e. correctly p...

replacing loop with cell of index values

s = 1:100; c{1} = 1; c{2} = 1:5; c{3} = 2:2:10; out = cellfun(@(x)s(x),c,'uni',0); out{:} A well-written (i.e. correctly p...

9 days ago | 1

| accepted

Answered

Colors in Matlab as a vriable

Perhaps something like this: M = [1,0,0;... red 1,1,0;... yellow 0,1,0]; % green X = strcmpi(Auto.Farbe,{'red','ye...

Colors in Matlab as a vriable

Perhaps something like this: M = [1,0,0;... red 1,1,0;... yellow 0,1,0]; % green X = strcmpi(Auto.Farbe,{'red','ye...

13 days ago | 0

Answered

Opening multiple .csv files using readtable

% opts is unchanged D = 'C:\Users\krist\OneDrive\Documents\MATLAB'; S = dir(fullfile(D,'*.csv')); for k = 1:numel(S) F =...

Opening multiple .csv files using readtable

% opts is unchanged D = 'C:\Users\krist\OneDrive\Documents\MATLAB'; S = dir(fullfile(D,'*.csv')); for k = 1:numel(S) F =...

13 days ago | 1

| accepted

Answered

How to create matrix with other matrixes by joining them?

a = [1 2 3]; b = [4 5 6]; c = [7 8 9]; d = [10 11 12]; res = reshape([a;c;b;d],2,[])

How to create matrix with other matrixes by joining them?

a = [1 2 3]; b = [4 5 6]; c = [7 8 9]; d = [10 11 12]; res = reshape([a;c;b;d],2,[])

14 days ago | 2

| accepted

Answered

saving the data in a variable

"...how to change the name of the file when matlab saves it" That is easy: https://www.mathworks.com/help/matlab/import_export...

saving the data in a variable

"...how to change the name of the file when matlab saves it" That is easy: https://www.mathworks.com/help/matlab/import_export...

14 days ago | 0

Answered

How to iterate over cell array, creating only unique combinations of cells

data = {1,2;3,4}; n = numel(data); m = nchoosek(1:n,2) % each row is one combination pair. out = data(m) % output [idr,idc] ...

How to iterate over cell array, creating only unique combinations of cells

data = {1,2;3,4}; n = numel(data); m = nchoosek(1:n,2) % each row is one combination pair. out = data(m) % output [idr,idc] ...

14 days ago | 0

| accepted

Answered

how to arrange data into array

Without an intermediate sparse array: R = [1;2;3;4]; C = [10;11;13;15]; V = [1e-5;5e-5;10e-5;15e-5]; % S = max([R,C],[],1);...

how to arrange data into array

Without an intermediate sparse array: R = [1;2;3;4]; C = [10;11;13;15]; V = [1e-5;5e-5;10e-5;15e-5]; % S = max([R,C],[],1);...

14 days ago | 0

Answered

How to count the number of times that values changes?

A = [1;1;1;2;1;3;3;1;1] B = [NaN;cumsum(diff(A)~=0)]

How to count the number of times that values changes?

A = [1;1;1;2;1;3;3;1;1] B = [NaN;cumsum(diff(A)~=0)]

15 days ago | 3

| accepted

Answered

Getting rid of loops

Logical indexing is much simpler than using loops: idx = A<1 & A>0; A(idx) = B(idx); A(A<C) = NaN; idy = B>100 | B<0; ...

Getting rid of loops

Logical indexing is much simpler than using loops: idx = A<1 & A>0; A(idx) = B(idx); A(A<C) = NaN; idy = B>100 | B<0; ...

15 days ago | 0

| accepted

Answered

How to conditionally merge rows in a table

lat = [45.67, 45.67, 56.89, 78.61]'; lon = [-66.45, -66.45, -65, -67]'; id = [202, 202, 201, 200]'; key = {'A', 'B', 'C', 'C'...

How to conditionally merge rows in a table

lat = [45.67, 45.67, 56.89, 78.61]'; lon = [-66.45, -66.45, -65, -67]'; id = [202, 202, 201, 200]'; key = {'A', 'B', 'C', 'C'...

16 days ago | 0

| accepted