Answered
Return the position of a vector in a cell array that is length 3
>> C = {[1,2,3],[3,4,2,1],[1,2]}; >> X = cellfun(@numel,C)==3 % logical index X = 1 0 0 >> find(X) % linear index ans = ...

6 years ago | 0

| accepted

Answered
Using for loop to load multiple mat files of same names
Try something like this: N = 20; D = 'path to the folder where the files are saved'; for k = 1:N F = fullfile(D,sprintf(...

6 years ago | 0

| accepted

Answered
Replace a single character with a new line in a string
>> str = 'hello there how are you today'; >> regexprep(str,'w','\n') ans = hello there ho are you today And to remove that ...

6 years ago | 0

| accepted

Answered
Trying to get a symbolic derivative from a string that the user inputs
Use str2sym: https://www.mathworks.com/help/symbolic/str2sym.html

6 years ago | 1

| accepted

Answered
Converting floating-point hexadecimal (string input) to decimal
>> str = '2B.3A'; >> out = sscanf(str,'%lx.'); % use NUMEL(OUT) to detect integer or fractional >> dcp = numel(str)-strfind(st...

6 years ago | 0

| accepted

Answered
Merge cell that has common element
Simpler: A = {[1,2;1,3;2,4;3,4;2,5],[72,73],[5,6;6,7],[36,39],[71,80;72,80],[27,70;28,71],[39,51],[21,29]}; ii = 1; while ii<...

6 years ago | 1

Answered
Generating all possible products from set of values
One simple solution (although it does change the size of A on each iteration). C = {[1,2,3],[4,5],[6,7,8,9]}; % much better in ...

6 years ago | 0

| accepted

Answered
Plot function handle with vector input
newfun = @(x,y)yourfun([x,y]); fsurf(newfun) Could be generalized for any number of inputs: newfun = @(varargin)yourfun([vara...

6 years ago | 0

| accepted

Answered
Extracting from vector to multidimensional array using indices provided
In three lines (could be just one), no loops, and yes that extra 6 is taken into account! >> D = [1,1,1,1,1,4,4,4,4,4,7,7,7,7,7...

6 years ago | 0

| accepted

Answered
Matrix function for subtracting and adding numbers from values in a matrix
M = [0,0,0;0,9,0;0,0,0]; C = [0,1,0;1,-4,1;0,1,0]; while any(M(:)>4) M = M + conv2(+(M>4),C,'same'); end

6 years ago | 2

| accepted

Answered
Matlab: Select a variable name and find the corresponding value
One simple regular expression: str = fileread('test.subvar'); rgx = 'Wk1_(lr|voll)_m\D+(\d+)'; tkn = regexp(str,rgx,'tokens')...

6 years ago | 2

Answered
Generating a 3D matrix from multiple tables
'I have 469 scripts that all generate a table "numericData"... I wrote a code that loads the files...' There appears to be some...

6 years ago | 1

| accepted

Answered
How to use elements i, j to print a 5x5 matrix
>> [I,J] = ndgrid(1:5); >> A = 1./(2.^I+3.^J); >> F = [repmat(' %9.7f',1,5),'\n']; >> fprintf(F,A.') % note the tranpose! 0...

6 years ago | 1

| accepted

Answered
Taking values out of a vector
"What is the meaning of the following statement?" It really is just basic MATLAB operations. 1- The square brackets and the co...

6 years ago | 1

| accepted

Answered
Replacing values in a logical vector based on a rule
Try using logical indexing rather than a loop: idx = strcmp(Group1_KOs.BehaviourType, Behaviours(n)); tmp = double(idx); tmp(...

6 years ago | 0

| accepted

Answered
How do I manipulate matrix elements conditionally without loops?
Just assign A to a new variable first, and then use indexing afterwards. It will be clearer if you define the index as its own v...

6 years ago | 1

| accepted

Answered
checking value greater than threshold
>> A = [10,42,55;63,52,81;30,52,14]; >> k = A.*(A>50) k = 0 0 55 63 52 81 0 52 0

6 years ago | 0

| accepted

Answered
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
Use an ellipsis (three dots) to continue code onto the next line: s1 = servo(a, 'D9', 'MinPulseDuration', 700*10^-6, 'MaxPulseD...

6 years ago | 0

Answered
Conversion to single is out of range
The keyword here is normalized. Note that the realmin documentation clearly states "Smallest normalized floating-point number" ...

6 years ago | 2

| accepted

Answered
Concatenate cell and integer array horizontally
You will need to convert the integer array into a cell array, e.g. using num2cell: for k = 1:size(Group1_KOs,2) Group1_KOs...

6 years ago | 0

| accepted

Answered
Import Multiple Text Files into multiple arrays
D = 'path to the directory where the files are saved'; V = 0:30:1830; N = numel(V); C = cell(1,N); for k = 1:N F = spri...

6 years ago | 0

| accepted

Answered
Find maximum of all rows without a for-loop?
Assuming that your three vectors have size 1xN (i.e. row vectors): M = [value_A;value_B;value_C]; T = max(M,[],1) Assuming th...

6 years ago | 1

| accepted

Answered
save all columns into a new variable in a loop
Use indexing: T = nan(3,1000); % preallocate! for k = 1:3 T(k,:) = myfunc(X,r); end

6 years ago | 0

| accepted

Answered
How to find out index number bewteen two arrays
You could use ismembertol like this: >> A = [11.6,56.9,30.5,80,34,78.98,34.01,3,1.5]; >> B = [56.9,1.5,3,30.5]; >> [X,Y] = i...

6 years ago | 0

| accepted

Answered
help extracting numbers from table of mixed strings
Simpler with a regular expression. Here I used a cell array of char vectors, but it will also work with a string array. str = {...

6 years ago | 0

| accepted

Answered
How to count number of occurences of each value in a vector and put the number beside the value as a new column?
>> V = randi(9,13,1) V = 6 4 4 2 9 5 1 6 2 1 6 9 4 >> [N,X] = histc(V,uniq...

6 years ago | 1

Answered
loading multiple groundtruth .mat files
Always load into an output variable (which is a scalar structure), e.g.: F = {'Beat1GTruth.mat', 'Beat2GTruth.mat', 'Fight1GTru...

6 years ago | 0

Answered
How do you write a script to create new events that requires multiple conditions?
You cannot use or like that. Probably ismember does what you want: ismember({sRaw.F.events.label}, {'50','52'})

6 years ago | 0

Answered
Add bits before last alphabet of every word
Simpler: >> str = 'A quick brown fox, jumps over the lazy dog'; >> out = regexprep(str,'(\w)\>','\x202D$1') out = A quick ...

6 years ago | 1

Answered
Strange behavior of "sort" function
Your first example is just a coincidence, but that is NOT the correct way to get the original vector order. The correct way to ...

6 years ago | 1

| accepted

Load more