Answered
Read a file with textscan.
opt = {'Delimiter',',','Headerlines',6,'CollectOutput',true}; fmt = ['%{uuuuMMddHHmmss}D',repmat('%f',1,12)]; fid = fopen('new...

4 years ago | 0

Answered
Split and count unique string in cell array
A = {'B25';'A35';'L35 J23';'K32 I25';'B25'}; B = regexp(A,'\S+','match'); T = cell2table([B{:}].'); S = groupsummary(T,'Var1'...

4 years ago | 0

| accepted

Answered
Numbers from a csv are not being read as doubles, but as chars?
"...I was forced to edit the original csv..." That is the cause of your problem right there. Let me guess: you made the mistake...

4 years ago | 1

| accepted

Answered
Why is spline doing weird stuff with my data?
I don't see any "weird stuff": X = [119645.85786265088;146646.66450412222;202133.69044903992;278604.3016284374;352333.877275211...

4 years ago | 0

Answered
only use filepath if it is a log file
P = 'absolute or relative path to where the files are saved'; S = dir(fullfile(P,'*.log')); for k = 1:numel(S) F = fullfi...

4 years ago | 0

| accepted

Answered
Why is my coding stopping at the shotscore vector when using fprintf?
fprintf('%3.0f %6.2f %6.2f %6.3f %3.0\n',[numbers x y shot shotscore]') % ...

4 years ago | 0

Answered
Difference of elements of vector and matrix
A = [1,2,3,4;5,6,7,8] B = [1,3] [X,Y] = ismember(B(1,:),A(1,:)); C = A(:,Y(X))

4 years ago | 1

| accepted

Answered
reallocating matrix concatenated as string
Much better to use string arrays: M1 = [10,22,42;193.92,68.8,9.34;193.92,68.8,9.34] M2 = [10,22,42;8,7,1;8,7,1] S = M1+"-"+M2...

4 years ago | 0

| accepted

Answered
create a new variable based on excel sheet values
fnm = 'test.xlsx'; snm = sheetnames(fnm) dat = cell(size(snm)); for k = 1:numel(dat) dat{k} = readmatrix(fnm,'Sheet',snm...

4 years ago | 1

| accepted

Answered
I have a table with names of structures present in the workspace, I need to access each Structure by getting the name from the table and update the respective structure field
Put all of the tables into one cell array and then use basic indexing. Or use the fields of a structure, e.g.: https://www.math...

4 years ago | 0

Answered
How to select time range for many years?
Do NOT use deprecated DATENUM, DATEVEC, or DATESTR. Use the methods and properties of the DATETIME objects: DT = datetime(2010...

4 years ago | 1

| accepted

Answered
convert an array value into corresponding Matrix indices
A = repmat((1:10).',3,1) M = (1:10)==A

4 years ago | 0

| accepted

Answered
How to convert row-major linear indices to column-major indices?
S = [3,6]; % matrix size X = [1,8,14,9,4,11,18]; % row-major linear indices [Y,Z] = ind2sub(flip(S),X); V = sub2ind(S,Z,Y) % ...

4 years ago | 0

| accepted

Answered
How to unzip multiple files(zipped) present in different subfolders
inp = 'absolute or relative path to Folder 1'; out = 'absolute or relative path to the output folder'; unzip(fullfile(inp,'nam...

4 years ago | 1

Answered
Converting location of a 2x3 vector into a matrix with value 1
"However for a large matrix a this will be tedious." If you have a large matrix it may be better if it were a sparse array (whi...

4 years ago | 1

Answered
How to shuffle rows in pairs?
V = 1+mod(0:599,8).' % fake data M = reshape(V,2,[]); X = randperm(size(M,2)); V = reshape(M(:,X),[],1)

4 years ago | 1

Answered
Preallocating for speed with increments
Indexing would be a much better approach, rather than those inefficient low-level loops. Note that it is not that loops are gene...

4 years ago | 0

| accepted

Answered
Manipulating a structure for a more flexible plot
Data in a 3x1 structure array (rather than a scalar structure with nested cell arrays as you showed) means slightly simpler data...

4 years ago | 0

| accepted

Answered
Efficient way of performing operation on array after performing cumsum
A = [1,2,3;4,5,6;7,8,9]; B = cumsum(A,2); C = B./(1:3)

4 years ago | 2

| accepted

Answered
fgets write -1.000000e+00 in output file
while ~feof(file)

4 years ago | 0

| accepted

Answered
I'm trying to initialize a structure from a txt file which contains matrices and the field names
Assuming that every "system" contains exactly the same number of matrices: str = fileread('database_z.txt'); tkn = regexp(str,...

4 years ago | 1

| accepted

Answered
Concatenation of matrices with a specific pattern
N = 4; A = rand(3,3,N); B = rand(3,3,N-1); C = rand(3,3,N-1); D = repmat({zeros(3,3)},N,N); D(diag(true(1,N))) = num2cell...

4 years ago | 1

| accepted

Answered
How to check if all the data in the cell array are the same?
The simple and very efficient MATLAB approach is to use a comma-separated list: https://www.mathworks.com/help/matlab/matlab_pr...

4 years ago | 1

Answered
Sum matrix with repeating indices
A simple MATLAB approach: A = [1,2;1,-3;2,0;3,3;5,6;2,-4;4,0.5;7,9;7,2] [G,U] = findgroups(A(:,1)); M = [U,accumarray(G,A(:,2...

4 years ago | 0

| accepted

Answered
Adding Matching Data from multiple rows
Name = ["One";"Two";"Three";"One";"Two";"Three";"One";"Two";"Three";"Three"]; Num = [6;3;1;5;22;2;6;3;32;4]; inp = table(Name,...

4 years ago | 0

| accepted

Answered
Create a matrix composed of cross column per element moltiplication
B = (1:9).'+(0:3) N = size(B,2); V = nchoosek(1:N,2); M = B(:,V(:,1)).*B(:,V(:,2))

4 years ago | 0

| accepted

Answered
How to write my function output in various form?
This is how to do achieve what you asked for: function [out1,out2,out3,out4,out5,out6,out7] = yourFunction(..) .. out1 = ..; ...

4 years ago | 1

| accepted

Answered
Creating matrix from a loop between multiple files
Use arrays and indexing rather than numbered variable names. Use a more appropriate tool for importing textfile data, e.g. READ...

4 years ago | 2

| accepted

Answered
Joining tables with different number of coloums
"From my understanding there is no need for the number of coloums to be the same" If the number of columns in the key variables...

4 years ago | 0

| accepted

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

Load more