Answered
Substracting previous value in a matrix and assigning it to a new matrix
a = [ 1.6766 0.6118 0.3707 0.0771 0.0010 0.2057 0.1219 0.2438 2.2065 0.8679 0.4766 0.087...

5 years ago | 0

| accepted

Answered
Findgroups, order of unique values in an array
[ID,~,G] = unique(labels_all,'stable')

5 years ago | 0

| accepted

Answered
Convert matrix to cell knowing the number of components to have in each cell
idx = [2;4;3]; data = [ 0.7922 0.3922 0.9595 0.6555 0.6557 0.1712 0.0357 0.7060 0.8491 ...

5 years ago | 1

| accepted

Answered
storing values of for loop in a matrix
x = -60:0.5:-50; y = -10:0.5:-5; z = nan(numel(x),numel(y)); % better to preallocate array. for i = 1:numel(x) for j = 1...

5 years ago | 0

| accepted

Answered
Can I use logical indexing to find how many times a character is in a string?
You can perform logical comparisons on a character array (they are not very different from numeric arrays): str = 'some random ...

5 years ago | 1

| accepted

Answered
How to quickly obtain the row indices in the original matrix A for a sub-matrix B?
[~,Y] = ismember(B,A,'rows')

5 years ago | 0

| accepted

Answered
Efficient indexing. Index array generating.
data = 1:1000; array1 = 1:10:101 idx = array1(:)+(0:2); out = data(idx)

5 years ago | 0

| accepted

Answered
How can i output an answer when making an app so that it has a set number of decimal places.
sprintf('%.3f',0.07) sprintf('%.3f',1)

5 years ago | 1

Answered
Index exceed the number of array elements
tmp = find(V_ref == V_Target):max(V_ref); for v = reshape(tmp,1,[]);

5 years ago | 0

Answered
Combine each column of two array side by side and add new column to new array
A = [0.6 0.7 0.8; 0.2 0.5 0.25; 0.9 0.7 0.1] B = [11 12 13; 17 18 19; 21 24 26] C = reshape([A;B;A+B],size(A,1),[])

5 years ago | 0

| accepted

Answered
Afficient way to create "sum matrix"
g = 1:3; m = g+g(:)

5 years ago | 0

| accepted

Answered
How to get struct results in a loop?
data(i,:) = FnCarbona(i).ponteiro(); % ^^ indexing needs to specify what happens to all 50 elements.

5 years ago | 0

| accepted

Answered
Extracting specific data from a cell array
After the loop: M = vertcat(A{:}); out = M(:,[9,11])

5 years ago | 0

| accepted

Answered
Save each pair in container.Map to separate variable in .mat file
"Is there a better way to do this?" Of course, just use the -struct option when calling save. Note that conversion to structure...

5 years ago | 1

| accepted

Answered
how to convert cell array to matrix
Where C is your cell array: M = horzcat(C{:}).'

5 years ago | 0

| accepted

Answered
Convert a cell with structures into a matrix
Rather than inefficiently storing lots of scalar structures in a cell array, you should just use one efficient non-scalar array,...

5 years ago | 0

Answered
Counting the number of the unique value in each row of a matrix without using for loop
M = randi(9,5,7) N = 1+sum(diff(sort(M,2),1,2)~=0,2)

5 years ago | 2

| accepted

Answered
I only need the output from the last iteration
Wrap disp in a suitable if statement, e.g.: if j==N disp(..) end

5 years ago | 0

| accepted

Answered
How to split datetime vector into a numerical Matrix?
M = [t2.Year(:),t2.Month(:),t2.Day(:)] or use the first three columns: M = datevec(t2)

5 years ago | 1

| accepted

Answered
Identify the file number from the folder
D = 'absolute or relative path to where the files are saved'; S = dir(fullfile(D,'R*.bmp')); V = sscanf([S.name],'R%fbmp')

5 years ago | 0

| accepted

Answered
How to find unique values in a matrix without looping over rows
M = randi([0,9],3,13) W = sort(M,2); W(diff(W,1,2)==0) = 0; W = sort(W,2) % optional

5 years ago | 0

Answered
Build matrix of different size column vectors generated inside a for loop
Inside the loop store the vectors in a preallocated cell array. Then after the loop use PADCAT (download required): https://www...

5 years ago | 0

| accepted

Answered
How to extract numeric data between string lines?
str = fileread('02-2021-Clearance-Box005_fort72.txt'); rgx = '(?<=Number of hit cells:\s+\d+\s+)(\d+[^\n]*)'; tmp = regexp(str...

5 years ago | 0

| accepted

Answered
Replacing a numberless string in matrix with a number
Where V is that column: V = ["female";"male";"female";"male";"male";"female"] X = strcmpi(V,"female")

5 years ago | 1

Answered
how to extract an extra variable which is calculated in ode function to main workspace?
Ignore advice that you should use assignin or evalin, because this does not take into account how ODE solvers work, as well as b...

5 years ago | 0

| accepted

Answered
Why does ishghandle(0) alwys return true?
Because the graphics root always exists: https://www.mathworks.com/help/matlab/creating_plots/graphics-objects.html Using zero...

5 years ago | 2

| accepted

Answered
pick elements from a 3d array, based on an indexing matrix
https://www.mathworks.com/help/matlab/ref/sub2ind.html % fake data: nr = 5; nc = 7; np = 3; A = randi(9,nr,nc,np); I = ran...

5 years ago | 0

| accepted

Answered
Loading data from structure, using variable
The most important step is to always load into an output variable (which itself is a scalar structure): S = load(...) % always ...

5 years ago | 2

| accepted

Answered
Sum per 2 elements in vector
A = [1;2;3;4;5;6]; B = A(1:2:end) + A(2:2:end) or more generally: B = sum(reshape(A,2,[]),1).' or B = reshape(A,2,[]).' * o...

5 years ago | 1

| accepted

Answered
Problem outerjoin two tables 20x1 ; 20x8
I don't see why outerjoin is required: newTable = [ArrayTime,ArrayZ]

5 years ago | 0

| accepted

Load more