Answered
How do I convert dates to days?
Your example and explanation are inconsistent: your explanation shows difference between adjacent dates, your example vector sho...

4 years ago | 1

Answered
How to replace zero with one automatically in MATLAB
Here are three approaches: M1 = repelem(eye(6,6),1000,1) M2 = kron(eye(6,6),ones(1000,1)) C = repmat({ones(1000,1)},1,6); M3...

4 years ago | 0

Answered
How to display superscript in the command window.
You can use these characters: https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts Lets try one: fprintf('y\xB2'...

4 years ago | 0

| accepted

Answered
picking numbers from matrix
M = [0,4,8;5,0,0;0,4,6;2,8,0;0,0,7] fh1 = @(v)v(randperm(numel(v),1)); fh2 = @(k)fh1(nonzeros(M(:,k))); V = arrayfun(fh2,1:si...

4 years ago | 0

| accepted

Answered
How can I print row number to matrix in matlab?
M = [1 0 1; 0 0 1; 1 1 0; 0 1 1] V = 1:size(M,1); Z = V(:).*M

4 years ago | 0

Answered
Compiling output vectors from each iteration of a for-loop into a Matrix
% New P and reaction force values with P2 varying P1_c = 1000; P2_c = -1000 : 100 : 1000; Fay_c = (P2_c + 2*P1_c)/3; Fdy_c ...

4 years ago | 0

| accepted

Answered
issue using 'sort'
The output is correct: just as the SORT documentation states, the second output is the index such that the first output can be o...

4 years ago | 0

Answered
how to add anew column to the table using MATLAB
M = randi(10,30,5); T = array2table(M,'variableNames',{'feat1','feat2','feat3','feat4','feat5'}) T.Class = repelem(["Healthy";...

4 years ago | 0

| accepted

Answered
Convert portion of matrix under the diagonal to column vector
Note that approaches which check if the data are zero (e.g. NONZEROS or ==0) are not robust, because you might have perfectly va...

4 years ago | 1

| accepted

Answered
Replace string values in a table
The simple MATLAB approach would be to use indexing: T = readtable('Typ.csv'); V = ["French";"Spanish";"Italian"]; T.Typ = V(...

4 years ago | 0

Answered
load variables in workspace except the ones with '.' in them
With a sufficiently old MATLAB release you can use this: https://www.mathworks.com/matlabcentral/fileexchange/42274-loadfixname...

4 years ago | 0

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

Load more