Answered
Find exact string match in a cell of strings
C = {'This is XYZ1','This is XYZ11', 'This is XYZ1111','This is XYZ1.0'}; str = 'XYZ1'; rgx = sprintf('%s(?=$|\\s)',str); reg...

4 years ago | 1

| accepted

Answered
Extracting 2 Far right characters
tt = {'United Kingdom TR';'United Kingdom SR';'United Kingdom WR';'Worldwide TC'}; pe = regexp(tt,'\w\w$','match','once')

4 years ago | 0

Answered
Dot indexing is not supported for variables of this type. - trying to create a function to upload files matrices
I am guessing that you have very badly-designed data, where the variable in the MAT file uses the same name as the file itself. ...

4 years ago | 1

| accepted

Answered
How to remove date and time columns after merging as date_time?
You can use REMOVEVARS: https://www.mathworks.com/help/matlab/ref/table.removevars.html Your code would be clearer if you use ...

4 years ago | 0

| accepted

Answered
Sort a variables in structure
Rather than forcing pseudo-indices into fieldnames, why not use an array with indexing (e.g. a cell array) ? Here are two ways ...

4 years ago | 0

Answered
Is there a good reason for choosing assert() over an if condition with an error?
"Is easier reading/fewer lines the only goal?" Why call two operators when you can call just one? It certainly can make the in...

4 years ago | 1

| accepted

Answered
How to stop data being overwritten in for loop?
Use a structure array, which allows you different numbers of rooms on each storey. A simple example: NmS = 5; % number of store...

4 years ago | 1

| accepted

Answered
Repeated elements in an array
A = [3 7 25 27 30 31 32 34 35 36]; B = [2 4 2 2 2 0 3 2 3 2]; Either define new variables: X = [true,diff(B)~=0]; C = A(X) ...

4 years ago | 0

| accepted

Answered
convert current date and time to char
Avoid deprecated DATESTR and DATENUM. one = datetime('now','Format','yyyy-MM-dd''T''HH:mm:ss''Z''') two = one - hours(6)

4 years ago | 2

Answered
Bad time format, import to datetime
"Bad time format" Good time format: it looks like a completely standard ISO 8601 timestamp https://en.wikipedia.org/wiki/ISO_8...

4 years ago | 1

Answered
Choose specific values from dataset
txt = fileread('demodata1.txt'); rgx = '^\s+\d+\s+(\S+)\s+(\S+)'; tkn = regexp(txt,rgx,'tokens','lineanchors'); mat = str2dou...

4 years ago | 1

| accepted

Answered
How do you build multiple cell arrays from the columns of an array?
M = randi(9,3,5) C = num2cell(M,1)

4 years ago | 0

| accepted

Answered
Extract data from sequentially named tables
"So after loading the files, I am left with tables I cannot call, because they are named sequentially..." Actually there is a r...

4 years ago | 2

Answered
How to import data from a .txt file with semicolons
Because you did not upload a sample file I had to create my own (attached). format short G mat = readmatrix('test.txt', 'Delim...

4 years ago | 0

| accepted

Answered
Different "kind" of variable
typ = ["oats","milk","water"] mat = [66,12,0;10,8,0;7,8,0] inp = ["milk","oats"]; qty = [2,0.5]; [~,idx] = ismember(inp,t...

4 years ago | 0

Answered
How to flip an array without using the flip command ?
F = [-0.5,4.5,-2.0,3.6,8.5,7.3,2.5,1.2,6.5] P = F(end:-1:1)

4 years ago | 0

| accepted

Answered
Problem with ploting exp function
"I think there is a problem with .*exp(x-y)" I doubt that. Did you look at the domains and ranges that you are plotting? Your ...

4 years ago | 1

| accepted

Answered
How to SUMIF similar to Excel
"Not sure where this is going wrong." Reinventing the wheel by writing lots of loops, and ignoring the inbuilt tools. dt = dat...

4 years ago | 0

Answered
i have a code that isnt running through all the if statements
The problem is how you have used IF and ELSIF. All character codes in the text 'skating' are all non-zero, so if ('skating') ...

4 years ago | 0

Answered
Convert a cell array (each cell having different no. of elements) to matrix
Download PADCAT from here: https://www.mathworks.com/matlabcentral/fileexchange/22909-padcat and use it like this: A = padcat...

4 years ago | 1

| accepted

Answered
Applying whos to each field of a struct
Using a nested function avoids the need for counting input arguments, simplifies the code somewhat, and might make collating the...

4 years ago | 0

| accepted

Answered
how to store every element of a cell array in a separate folders
As soon as you start numbering variable names like n1, n2, n3, ... then you have painted yourself into a corner and made your ta...

4 years ago | 1

Answered
need to convert a cell into a vector number
C = {'80,47,109,44,104,40'} % why is this in a scalar cell array? V = sscanf(C{:},'%f,',[1,Inf])

4 years ago | 0

| accepted

Answered
Variables created in different formats
Your file is not really a Comma-Separated Values (CSV) file, it actually uses a tab as the values delimiter and comma as the dec...

4 years ago | 0

| accepted

Answered
How do I make a section of a function runs only one time?
The MATLAB approach is to move that code outside of the function and parameterize the function call: https://www.mathworks.com/...

4 years ago | 0

Answered
How to convert all of a structures fields into strings that represent the complete names.
The only general solution is to use a recursive function. Here is code which works for scalar structures, although you could ext...

4 years ago | 0

| accepted

Answered
How to get the order if one column has same number and other column has different values
Simpler and more efficient using basic logical indexing: arg = [zeros(7,1);1;1;1] dtm = datetime(2022,2,25,19,[6;6;6;6;7;7;7;8...

4 years ago | 0

Answered
How can I copy lines of an external text file to another file
tmp = readlines('a.txt'); writelines(tmp(5:end),'new.txt')

4 years ago | 2

Answered
How to Swap alternate rows of a column matrix
Simple approach using indexing (only works for matrices with an even-number of rows): inp = randi(9,8,4) out = inp([2:2:end;1:...

4 years ago | 0

Answered
Input as the hexadecimal number
Since R2019b it is possible to directly enter literal hexadecimal and binary numeric values: https://www.mathworks.com/help/mat...

4 years ago | 0

Load more