Answered
How do you extract the elements of a cell that have the largest length?
C = {[7,8,9],[6,10],[4,5,6,7],[1,2,3,4]} N = cellfun('length',C); X = max(N)==N; D = C(X)

4 years ago | 0

Answered
convert 12 hour data to 24 hour datetime data for timetable
Edit: read the comments to handle ambiguous midday/midnight: https://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_...

4 years ago | 1

| accepted

Answered
How to save and change the position of some fields in a structure?
I think what you are looking for can be achieved using ISMEMBER. Basically you need: a way to identify any matches between the...

4 years ago | 0

| accepted

Answered
Separate multi-word comma separated cell into rows
More efficient than using CELLFUN: C = {'Business Name One[5],Business Name Two[3],Business Name Three[2]'; ... 'Business ...

4 years ago | 0

| accepted

Answered
How to import variable names and specific data range (comma separated values) from a .txt file?
Make sure you specify the delimiter and (start) Range for DETECTIMPORTOPTIONS: file_name = 'Earth-Moon_sys_ephem_at_ast_epochs....

4 years ago | 1

| accepted

Answered
Script that scans through a text file line by line, edits lines of a specified format, then saves edited lines into a new text file.
In lieu of your own uploaded data file I had to create my own (attached). Most likely it will not match your file format, which ...

4 years ago | 1

| accepted

Answered
Conversion of a binary matrix to decimal matrix
The most efficient approach would probably be to avoid type conversion (e.g. to character) and to avoid BIN2DEC. It is just as ...

4 years ago | 3

| accepted

Answered
Unable to control floating point display?
It would be better to use SPRINTF rather than NUM2STR. For example: Line1 = sprintf('(X,Y) = %u, %u', posX, posY); Line2 = spr...

4 years ago | 0

| accepted

Answered
Difficulty with using sscanf to perform natural order sort on filename list
Your question makes it unclear if you are looking for a general solution or a solution that is tailored for those specific filen...

4 years ago | 0

Answered
difference between rem and mod functions?
See: https://www.mathworks.com/matlabcentral/answers/403870-difference-between-mod-and-rem-functions#answer_323069 and the MOD ...

4 years ago | 1

| accepted

Answered
How to count how many sub folders under a folder
The correct answer would be something like this: P = 'absolute or relative path to the folder'; S = dir(P); N = nnz(~ismember...

4 years ago | 0

Answered
How to apply dec2bin to char array?
"there is a problem with more digits in a like a='12362534624362643243256346523462'..." The DOUBLE numeric class can only store...

4 years ago | 1

| accepted

Answered
How to retrieve unique columns in a matrix ?
A = [1,-1,1,1;1,1,1,1;2,1,1,1]; B = unique(A.','rows','stable').'

4 years ago | 0

| accepted

Answered
Reshape matrix with multiple columns into 2 columns
Of course, here are two general solutions. A = [1,2,3,4;5,6,7,8;9,10,11,12] B = [1,2;5,6;9,10;3,4;7,8;11,12] % desired output ...

4 years ago | 2

Answered
converting UTC time formatted as 'ddd:HH:mm:ss.SSSSSSSS' from a string to a date time.
A = '2022'; B = '036:19:45:30.123581351'; C = sprintf('%s:%s',A,B); D = datetime(C,'InputFormat','u:D:H:m:s.SSSSSSSSS') You ...

4 years ago | 0

| accepted

Answered
How to assign different files in the target folders?
P = 'absolute or relative path to where the files are saved'; for k = 1:31 D = sprintf('Day%02d',k); mkdir(P,D) ...

4 years ago | 0

| accepted

Answered
Create table from array in a loop
"to collected data so that these can be grouped in 5mm groups according to a Diameter values." The MATLAB approach would be to ...

4 years ago | 0

| accepted

Answered
How to use the output of a nested function in parent function?
If you define a function with output arguments and you then want to get those outputs then of course you will also need to call ...

4 years ago | 1

| accepted

Answered
how to input variables?
t = a./(b.^c) % ^ you forgot this Read this to understand the difference: https://www.mathworks.com/help/matlab/matlab_pro...

4 years ago | 0

| accepted

Answered
Selecting Mondays from a Timetable or Table using the datetime object
By default DAY returns the day of the month, so you need to specify its second argument like this: d = day(t,'dayofweek')

4 years ago | 0

| accepted

Answered
How can I divide a given range of three values into equal subparts like abc=[initial_values, mid_value, last_value] and expand the range into a total of 9 or 12 values?
The MATLAB approach is to use INTERP1, because what you ask about is exactly what interpolation is for: x = [80,160,240]; y = ...

4 years ago | 0

Answered
How to create this patterned matrix?
N = 8; M = toeplitz(0:N-1,[0,N:-1:1]); M(N,:) = N:-1:0

4 years ago | 0

| accepted

Answered
Regexp expression to handle changing format
You can easily make a group optional or occur a specific number of times using any suitable quantifier, for example: (..)? % ze...

4 years ago | 0

Answered
Find if two elements are in a row of a matrix
A = [1,3,7]; B = [1,8,3;1,2,3;3,4,5;1,7,9;2,1,3]; V = find(sum(ismember(B,A),2)==2)

4 years ago | 0

| accepted

Answered
How to store the non zero value from each column of a matrix as a column vector (but if there is only zeros on the column store zero) in each iteration?
The simplest solution is probably to use MAX: M = [0.38,0,0;0,0,0;0,0.58,0.71;0,0,0;0,0,0] V = max(M,[],1).' An example where...

4 years ago | 1

| accepted

Answered
How to save mat file using save() with a different variable name using for loop
"How to save mat file using save() with a different variable name using for loop" That rather poor data design that seems to be...

4 years ago | 0

Answered
How to read data using "regexp" function, even when there are occurrences of missing values.
Replace + with *, for example: (?<var1>\w*) % ^ I also simplfied your code and fixed some other bugs: str = fileread...

4 years ago | 0

| accepted

Answered
"ReadTable" column reading error/bug?
Simpler and more efficient: T = readtable('Attept2Pipeline_Perinuclear_Ring.csv', 'Delimiter',',') T = readtable('Attept2Pipel...

4 years ago | 0

| accepted

Answered
I want to get how many times a value sequence is repeated in a column and the average number of times it repeated in a sequence.
"suppose i have a column" V = [0;0;0;0;0;0;0;0;0;1;1;1;1;0;0;0;0;0;0;0;1;1;1;0;0;0;0;0;0;0;1;1;1;0;0;0;0;1;1;1;1;0;0;0;0;0;0;1;...

4 years ago | 0

Answered
How to save all outputs that are produced from each iteration in separated cell in one row of array and each row expresses an iteration then store it in one .mat file?
Pd = {}; [Pd{1:7}] = ndgrid([0.5,1]); Pd = reshape(cat(8,Pd{:}),[],7).'; C = 5*Pd; % M = your code is unclear save('cases....

4 years ago | 0

| accepted

Load more