Find column number for every row in matrix
M = [-1,4,1;1,-1,-1;-5,4,-1] Method one: logical array, CUMSUM, and FIND: X = M>=0; Y = X&cumsum(X,2)==1; [C,~] = find(Y.') ...

10 days ago | 0

| accepted

Creating a function to Import data into structures
[TrajX.(trialname),TrajY.(trialname),TrajZ.(trialname)] = Import_Data_Function(vicon,subject,firstframe,lastframe); function ...

10 days ago | 0

| accepted

Vertically Concatenating Timetables of Different Sizes
"The goal here is to vertically concatenate each timetable so that all the data within the intersection are aligned by column/di...

11 days ago | 0

| accepted

is there any way to convert milliseconds to hh:mm:ss.FFF.
N = uint32(65432) D = milliseconds(N); D.Format = 'hh:mm:ss.SSS'

11 days ago | 1

Working with structures : Unrecognized field name
"Do you have any ideas on how to get around this problem? " Field = fieldnames(s); Dat = s.(Field{1}).data https://www.mathwo...

11 days ago | 0

| accepted

how to reverse a matrix (nxm) sorting?
x = rand(3,5) [xs, is] = sort(x,2) Method one: NDGRID and SUB2IND: sz = size(x); [~,ic] = sort(is,2); [ir,~] = ndgrid(1:sz(...

12 days ago | 1

| accepted

How to convert time format of file date
"Hello, I want to convert the date string obtained by file.date to the format yyyymmdd_HHMMSS, i.e.," A much simpler and much m...

12 days ago | 0

| accepted

subdirectories in a for loop
P = 'F:/PhD/Swan pruebas/Iniciados/regreso/River/MorF Rs (Veg)'; S = dir(fullfile(P,'Output*','file.mat')); S = natsortfiles(S...

14 days ago | 0

Average product of arrays
T = readtable('pems_rawdata_NB.csv') F = @(c)cellfun(@(t) sscanf(strrep(t,'{',''),'%f,'), c,'uni',0); T = convertvars(T,{'flow...

14 days ago | 1

| accepted

Reading data from .txt files from a folder.
To make debugging unexpected data (sizes, types, values) easier, I usually find it easier to concatenate data after the loop: P...

15 days ago | 0

| accepted

Vectorising nested for loops
S = load('data.mat') list = S.list tdat = S.table_data k=0; out0 = struct('idx',[],'count',[],'size',[]); for i = 1:size(...

15 days ago | 1

Matlab not recognizing 'fit' function
Have you or any third-party function or toolbox made any changes to the MATLAB search path? Call https://www.mathworks.com/help...

15 days ago | 1

| accepted

Remove null rows from a structure before converting to table
S = struct('A',{[],[],1},'B',{[],[],2}) X = arrayfun(@(s)any(structfun(@isempty,s)),S); T = struct2table(S(~X))

15 days ago | 0

readmatrix ignores the first line of the data file
You can specify the RANGE as the starting row: M = readmatrix('sample.txt', 'ConsecutiveDelimitersRule','join', 'Range',1) I n...

16 days ago | 1

| accepted

Sort two array in the same way, but only one in size order
"The problem now is that I want the same rows that changed for x should be changed for y. " It is not a problem, because when y...

17 days ago | 1

| accepted

Sorting vectors into a 3-D grid efficently
Perhaps something like this. The elements of M need to be valid indices, which you can achieve using basic arithmetic operations...

18 days ago | 1

| accepted

Rewriting a file?
https://www.mathworks.com/help/matlab/ref/writelines.html Tip for the future: you are already using READLINES, so scroll right ...

18 days ago | 0

How can I separate individual years from a timetable?
S = load('DateStamp.mat') T = S.DateStamp [G,Y] = findgroups(T.date.Year); X = arrayfun(@(x)find(x==G), 1:max(G), 'uni',0); ...

19 days ago | 1

| accepted

"My query is what does the term stacking indicates..." MATLAB does not use the term "stacking" to refer to these kinds of opera...

19 days ago | 0

| accepted

How to rearrange a row vector into a pair wise column vector?
"I am sure there is a nice loop to do this, but I can't find a solution." This is MATLAB, so loops are not required: v = 1:21 ...

19 days ago | 0

| accepted

MATLAB poems -- let's hear 'em!
In MATLAB we write lines of code For solving problems, it's our abode With matrices and arrays We handle huge data trays And...

19 days ago | 0

Replace specific elements in strings
Here are two approaches: A = ["America (New York)"; "America (Manhattan)"; "Italy (Rome)"] B = strrep(strrep(A,' (',' - '),')'...

20 days ago | 0

Behavior with unspecified output arguments
"Has it always been this way?" Yes. Several MATLAB functions from waaaay back in the past use exactly this feature. For exampl...

22 days ago | 1

| accepted

How can I get the return of a constructed function as an array?
That is not how MATLAB works. Your code defines a matrix of zeros, but then you do nothing with that variable and simply replace...

23 days ago | 0

| accepted

Vectors of seeming identical length, are supposedly not equal in length, how to fix?

23 days ago | 0

| accepted

Creating an augmented matrix a set of matrices
A = cat(3,[1,3;0,1],[1,1;1,1],[0,0;0,0]); C = num2cell(A,1:2); X = 1+tril(toeplitz(1:numel(C))); C = [{zeros(2)};C(:)]; M = ...

23 days ago | 0

| accepted

find the closest datetime
I have a datetime column with the format HH:mm:ss.SSSS and for which I'm loooking for the closest datapoint to a time in a forma...

23 days ago | 0

| accepted

How to list all tasks in a table and sum up total time spend on each?
You can do this in just a few lines of code. Don't fight MATLAB with multiple nested loops! The data would be so much easier to...

24 days ago | 1