Community Profile # Stephen23

Active since 2014

Suspensa Vix Via Fit

Professional Interests:

#### Statistics

All
• • • • • • • • • • • • #### Content Feed

View by

storing excel data in matrix using for loop
n = 4; A = zeros(n,20); F = 'filename.xyz'; for y = 1:n S = sprintf('sheetname_%d',y); A(y,:) = readmatrix(F, 'Shee...

2 días ago | 0

Create new matrices based on the number of unique values
Those three matrices are a red-herring. M = [4,7,2;2,4,7;2,2,4] [U,~,X] = unique(M(:)); S = accumarray(X,M(:)) [~,Y] = max(S...

3 días ago | 1

| accepted

sum a column in a matrix
F = @(t) sum(t{:,7}); V = cellfun(F,Tables)

4 días ago | 1

| accepted

How can I avoid using addpath to read files outside Matlab's search folder?
" Is it correct that before files can be read by Matlab, the folder where files are located have to be added to Matlab's search ...

4 días ago | 0

| accepted

How to use outerjoin for multiple files
fnm = compose("file%d.csv",1:5); tbl = readtable(fnm(1)); tbl.Properties.VariableNames = {'Key1','Var1'}; for k = 2:numel(fnm...

5 días ago | 1

| accepted

Counting outcomes of names
str = ["Sam";"Joe";"TPG, Sam, Joe";"TPG, Joe"] spl = regexp(str,',','split'); [uni,~,idx] = unique(strtrim([spl{:}])); cnt = ...

5 días ago | 1

Make function in function
syms x g = 5*x f = g+3

5 días ago | 0

extract a number within brackets from a cell of a table
txt = '(2.59836893721600e+01dB,0.00000000000000e+00°)' num = sscanf(txt,'(%f')

5 días ago | 0

I want to loop for files in workspace
"Let's say I have data1, data2,... and dataN in my workspace." Lets assume that you did not name them all by hand, but instead ...

6 días ago | 0

| accepted

Extracting specific data from table
idx = startsWith(valores_sensores.ID,'ILM_'); % or CONTAINS SensorILM = valores_sensores(idx,:)

6 días ago | 0

| accepted

Concatenating matrix with specific cell in cell aray
C = {'hello',[1,2,5];'world',[3,5]} V = [4,5]; F = @(a)union(V,a); C(:,2) = cellfun(F,C(:,2),'uni',0)

9 días ago | 0

How can I create a 2-term, 1-by-1 string using sprintf?
Here is a way to import those badly-named variables, assuming exactly one variable per MAT file: N = 17; C = cell(1,N); for k...

9 días ago | 0

| accepted

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...

11 días ago | 1

| accepted

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

11 días ago | 0

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. ...

12 días ago | 1

| accepted

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 ...

12 días ago | 0

| accepted

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 ...

12 días ago | 0

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...

13 días ago | 1

| accepted

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...

13 días ago | 1

| accepted

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) ...

13 días ago | 0

| accepted

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)

13 días ago | 2

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...

13 días ago | 1

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

14 días ago | 1

| accepted

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

14 días ago | 0

| accepted

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...

14 días ago | 1

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...

15 días ago | 0

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...

15 días ago | 0

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)

15 días ago | 0

| accepted