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

Answered
Delete and replace a struct in a mat file
You can simply use the -append option, e.g. where var is the variable that you want to replace: var = [...]; fnm = 'name of th...

6 years ago | 0

Answered
Fzero using for loop
You need to parameterize the function: https://www.mathworks.com/help/matlab/math/parameterizing-functions.html Note that it i...

6 years ago | 0

| accepted

Answered
how to use function "find" over matrices
"find the first value in each column which lis ess than 0.25 but greater than 0.2." >> x = rand(13,7) x = 0.833676 0.654...

6 years ago | 1

| accepted

Answered
Struct to numeric variable
Apparently you have a 446x1 or 1x446 structure array, where the field in question contains a row vector. To concatenate all of t...

6 years ago | 0

| accepted

Answered
How to raise a decimal numbers as power of A??
Either use a loop or cellfun: >> A = [1,5,3;4,5,9;7,8,9]; >> V = 0.1:0.11:10; >> C = arrayfun(@(n)A^n,V,'uni',0); And checki...

6 years ago | 1

Answered
How to find and replace the content of an array
>> C = {'03/07/2019' '03/07/2019 00:30:00'}; >> X = cellfun('length',C)==10; >> C(X) = strcat(C(X),' 00:00:00') C = 03/07/2...

6 years ago | 0

Answered
How to load files in order
Use either of the methods shown in the documentation: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of...

6 years ago | 0

| accepted

Answered
How to create an array with repeating values of a vector
m = repmat(v,20,1) or m = v(ones(1,20),:) or m = ones(20,1)*v or m = zeros(20,1)+v % requires >=R2016b or [~,X] = ndgrid...

6 years ago | 1

| accepted

Answered
Function like "find" but for lines
>> B = find(A.').' B = 1 2 4 5 6 9 11 12

6 years ago | 1

| accepted

Answered
How can I remove identical cell entries containing small arrays
Two efficient loops, no third-party functions: S = load('example.mat'); C = S.connect_group; N = numel(C); X = true(1,N); f...

6 years ago | 1

| accepted

Answered
Matrix split in vector
>> B = nonzeros(A.') B = 1 2 3 4 5 6 7 8

6 years ago | 0

| accepted

Answered
Import data as a structure array from a text file with different titles in the middle.
opt = {'MultipleDelimsAsOne',true}; out = {}; [fid,msg] = fopen('datafile.txt','rt'); assert(fid>=3,msg) while ~feof(fid) ...

6 years ago | 0

| accepted

Load more