Answered
Load stored handles data to an other function
"I think that something is missing in this ligne" Actually you already have too much on that line. Try this: DataNeed = handle...

6 years ago | 0

| accepted

Answered
How can we convert a datetime into a string that represents a Unix timestamp in nanoseconds?
Warning: this answer delves into undocumented features of the datetime object and relies on my own wild speculation that may be ...

6 years ago | 1

| accepted

Answered
What does '* *' mean in matlab?
The double asterisk tells dir to recursively search the provided path, the documentation explains it with "and dir **/*.txt list...

6 years ago | 1

Answered
Incorrect Logical Condition Statement
Leg = 'L'; %change between L and R vnm = sprintf('knee_flex_%s',lower(Leg)); Tables.(vnm) https://www.mathworks.com/help/matl...

6 years ago | 0

Answered
find the multiple max values
Where M is your matrix: >> U = unique(M(:)); >> X = ismember(M,U(end-2:end)); >> M(~X) = 0 M = 0 0 44 0 44 ...

6 years ago | 0

Answered
Import name/value parameters from a text file to a struct (or cell array)
As far as I am aware there isn't anything inbuilt. But you can do something like this: >> str = fileread('myparamfile.txt'); >...

6 years ago | 0

| accepted

Answered
Error using vertcat - Dimensions of arrays being concatenated are not consistent
R2 = [3; 4; -3.5; 3.5; 3.5; -3.5; -5; -5 5; 5]; % ^ missing semi-colon

6 years ago | 1

| accepted

Answered
interpolation for a matrix per row
You forgot the indexing here: interp1(t0,(RESULTS.Kinematics(j).data),t1,'linear') % ^^^ missing

6 years ago | 0

| accepted

Answered
populate matrix columns based on a vector of index vector
>> X = (1:5)>=B(:); % requires >=R2016b, for earlier versions replace >= with BSXFUN >> [R,~] = find(X); >> A(X) = C(R) A = ...

6 years ago | 0

| accepted

Answered
How to access data in a nested structures
"Is this the correct way?" The usual MATLAB way is to use two lines, e.g.: tmp = [a.b]; out = [tmp.c]; "Why does this not wo...

6 years ago | 0

| accepted

Answered
How to Save multiple results into one array
n = numel(x); xvalue = zeros(2,n); for ii = 1:n xvalue(:,ii) = mink(abs(Lx-x(ii)),2); end xvalue = xvalue(:).'

6 years ago | 1

| accepted

Answered
pre allocating triple loops
n = numel(L); c = cell(n,n,45); for ii = 1:n for jj = 1:n for kk = 1:45 c{ii,jj,kk} = cross...

6 years ago | 0

| accepted

Answered
Can I change this?
The most efficient solution is likely to be >> X = [1,1,1,0,1,0,0,0,1,0]; >> A = sprintf('%u',X) A = 1110100010

6 years ago | 1

Answered
How to naming for this? MATLAB Question
Numbering variables like that is not a good way to write MATLAB code. You could do that, but you force yourself into writing slo...

6 years ago | 0

| accepted

Answered
Take string input and reformat as cell array
>> str = fileread('SampleData.txt'); >> str = regexprep(str,{'",','[":{}\[\]]+'},{' ',''}); >> fmt = '%*s%{yyyy-MM-dd''T''HHmm...

6 years ago | 0

| accepted

Answered
How to name each element in a dataset after their row and column names?
>> M = randi(9,4,4) % random data M = 7 5 6 1 5 9 2 2 3 7 5 8 9 8 7 9 >> X = triu(true...

6 years ago | 1

| accepted

Answered
'Matrix dimensions must agree' error on string operations
"...don't really know what's wrong." What you wrote performs an element-wise comparison of the character in two character array...

6 years ago | 0

| accepted

Answered
How to calculate the syms with variable has the same name?
function out = myfun(exp,a,b) fun = str2func(sprintf('@(a,b)%s;',exp)); out = fun(a,b); end Tested: >> myfun('a>0',3,2) an...

6 years ago | 0

Answered
I am trying to create a loop that will be able to automatically follow a certain order of operations.
>> C = {'TP','TP','TP','TP','NaN','NaN','Px'}; >> [~,idx] = sort(strcmpi(C,'NaN')) idx = 1 2 3 4 7 5 6 and th...

6 years ago | 1

| accepted

Answered
create vector from each element it had
Method one: nonzeros: vec = [x,y,z]; tmp = 1:max(vec); new = nonzeros((tmp(:)<=vec).*tmp(:)).' % requires >=R2016b Method tw...

6 years ago | 0

| accepted

Answered
regexp to return folders
Why not just specify the name format to only return names that start with 'sub-', e.g.: S = dir(fullfile(parent_path,'sub-*'));...

6 years ago | 1

| accepted

Answered
How to load files in numerical order?
One simple way is to download my FEX submission natsortfiles: https://www.mathworks.com/matlabcentral/fileexchange/47434-natura...

6 years ago | 1

| accepted

Answered
Use string or character arrays in code?
"Which is preferred and why?" In my opinion character arrays and string arrays have quite different applications, even though p...

6 years ago | 1

| accepted

Answered
Making two data appear side-to-side
Try this: fprintf('%2.4f\t%2.4f\n',[array(:),Sw_C(:)].')

6 years ago | 1

| accepted

Answered
Values not getting printed in csv file
"Values not getting printed in csv file" Actually they are getting printed, your code just keep overwriting them. The problem i...

6 years ago | 0

| accepted

Answered
How delete duplicate strings in cell array
You could easily hide the loop inside cellfun, e.g.: >> fun = @(c)sprintf(' %u',unique(sscanf(sprintf(' %s',c{:}),'%f'))); >> ...

6 years ago | 0

| accepted

Answered
Sum Of Series variables from Vector.
Why not just use a loop?: Q = [1,2;3,4]; R = 5; z = [1;1;3;0;0;5;7;2;0]; % X = [z(1:3:end),z(2:3:end)].'; U = z(3:3:end)....

6 years ago | 0

| accepted

Answered
How to read line with multiple separate headers and tabs in between values
Importing the matrix data as numeric is much easier: opt = {'CollectOutput',true}; [fid,msg] = fopen('sample.txt','rt'); asse...

6 years ago | 0

Answered
saving variables programmatically using list of variable names
The simple solution is to use a comma-separated list: varNames = {'a','b','c'}; save('myMatFile',varNames{:}) % ...

6 years ago | 1

| accepted

Answered
Separating and sorting a character string of magnetometer data (X,Y,Z,temperature) into separate arrays of doubles
>> str = 'X-123.3 Y30.3 Z500.4 t24.5'; >> tkn = regexpi(str,'([A-Z]+)(\S+)','tokens'); >> tkn = vertcat(tkn{:}) tkn = '...

6 years ago | 0

| accepted

Load more