Answered
How to sequentially read .txt file to .mat with random names available in a folder
Sorting the filenames into alphanumeric order is not required for your task. The code below: Does not require the subject numb...

4 years ago | 0

Answered
Combining a number and a string array (both columns) into a single column string array.
The simple MATLAB approach: V = linspace(1,10,10); S = "X=" + V(:)

4 years ago | 1

Answered
Using 'Char' Information As A Variable Name
That would be complex and very inefficient. Your suggested approach is best avoided. A much simpler approach is to store the im...

4 years ago | 0

Answered
Use string name as variable name for struct
D.A__B__C = 0.5; D.A__B__D = pi F = fieldnames(D); C = regexp(F,'_+','split'); Z = struct(); for k = 1:numel(F) Z = se...

4 years ago | 0

| accepted

Answered
How to import data of the form [variable name]Data[-]
rgx = '\[(\w+)\]\s*([^\[]+)\[\-\]'; str = fileread('test.txt'); tkn = regexp(str,rgx,'tokens'); tkn = vertcat(tkn{:}); tmp =...

4 years ago | 1

| accepted

Answered
Why values get changed while doing indexing?
"Why values get changed while doing indexing?" They don't. The values are exactly the same, they are simply displayed slightly...

4 years ago | 0

| accepted

Answered
How to create a matrices using while loop?
r = 0.1; y = 2.5; i = 0; a = []; % <--- while i<=5 i=i+1; dis = r.*sin(y.*i); tim = dis*2; a = [a;i,dis,...

4 years ago | 1

| accepted

Answered
Sort repetition in text
T = 'KKKKLLOOKkl'; D = [true,diff(T)~=0]; L = diff(find([D,true])); C = compose('%s%d',T(D).',L(:))

4 years ago | 1

Answered
Turn table columns into rows
https://www.mathworks.com/help/matlab/ref/rows2vars.html

4 years ago | 0

| accepted

Answered
Move an element in a vector
V = 1:5; N = numel(V); A = repmat(1:N,N,1); [~,X] = sort(tril(1+A,-1)+eye(N)+triu(A,1),2); Z = V(X)

4 years ago | 0

| accepted

Answered
Loop through multiple levels of subfolders to run .mat files
P = 'absolute/relative path to the main directory'; S = dir(fullfile(P,'**','*.mat')); for k = 1:numel(S) F = fullfile(S(...

4 years ago | 0

| accepted

Answered
How to extract numbers from a string between a special character?
str1 = 'aa_100_6'; str2 = 'aa_1000_10'; str2double(regexp(str1,'\d+','match')) str2double(regexp(str2,'\d+','match')) Or if ...

4 years ago | 0

Answered
How to use a filename character array as a name of a variable?
A very neat and simple approach is to import the data into the same structure that DIR returns: P = 'absolute or relative path ...

4 years ago | 0

Answered
elegant way to initialize or add on end of a variable
numbers = 100*rand(100,1); high_numb = []; % empty! low_numb = []; % empty! for i=1:1:size(numbers,1) if numbers(i)>99 ...

4 years ago | 0

| accepted

Answered
Table Assignment using two tables of different height.
You can use ISMEMBER like this: T1 = array2table([8,5;9,9;2,9;9,2;6,9;1,9;3,5]) T2 = array2table([6,0;7,0.1;8,0.2;9,0.3]) [X,...

4 years ago | 0

| accepted

Answered
Reading the last line of each vector in a cell
After the loop, all at once: fnh = @(m)m(end,1:5); tmp = cellfun(fnh,Data,'uni',0); out = vertcat(tmp{:}) Or individually: ...

4 years ago | 0

Answered
How to merge multiple structures into one structure or a table?
The MATLAB approach, these are all equivalent: merged = [result1.values]; merged = cat(2,result1.values); merged = horzcat(re...

4 years ago | 0

| accepted

Answered
For Loop that Checks 2 Matrices to create a Combined New one based on IF Statement
Here is a direct translation of your Excel formula: T = readtable('Data.xlsx') % import your data nmr = height(T); out = zero...

4 years ago | 0

| accepted

Answered
What is the meaning of "Trailing string must be 'omitan' or 'includenan' " on MATLAB. I run the programm below but this error message displays
The 'all' option is not available in your version (R2016a). It was introduced in R2018b: https://www.mathworks.com/help/matlab/...

4 years ago | 1

| accepted

Answered
How to use a for cycle for opening .mat files
The general concept is shown here: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html You ca...

4 years ago | 2

| accepted

Answered
list MATLAB functions with a script
Use this: https://www.mathworks.com/help/matlab/ref/matlab.codetools.requiredfilesandproducts.html possibly with the '-toponly...

4 years ago | 0

Answered
Convert character vector to evaluable expression
S.field1.subfield = 5; % do NOT use STRUCT as a variable name. vec = 'S.field1.subfield'; spl = split(vec,'.'); val = getfiel...

4 years ago | 0

| accepted

Answered
Extracting data from text file
Method one: TEXTSCAN: fmt = '%s%f%f%f'; opt = {'MultipleDelimsAsOne',true, 'CollectOutput',true, 'HeaderLines',1}; fid = fope...

4 years ago | 0

| accepted

Answered
Extracting Time Data from Text File
Simpler and more efficient: str = fileread('test_1.txt'); tkn = regexp(str,'^\s*(\d+):\D+(\d+\.?\d*)\W+([^\n\r]+)', 'tokens', ...

4 years ago | 1

| accepted

Answered
How to extract the result after each iteration while using for loop?
With MATLAB it is almost always better to loop over indices rather than over data values. That makes it easier to save the data ...

4 years ago | 1

| accepted

Answered
How can you write a matlab code from the 2018 version back to the 2013b version?
"How can you write a matlab code from the 2018 version back to the 2013b version" By very carefully reading the documentation f...

4 years ago | 0

Answered
Save data from subfolders into a cell array
P = 'absolute or relative path to where the subfolders are'; N = 'the name of the file that you want.CSV'; S = dir(fullfile(P,...

4 years ago | 0

| accepted

Answered
How to arrange a column vector into two columns?
Assuming that the missing 236/237 row is a mistake: x = [128,147,166,181,195,216,236,255] m = [x(1),1+x(2:end-1);x(2:end)].'

4 years ago | 0

| accepted

Answered
I want to write a loot to open multiple files with fopen and stack it with fscan but my code does not work. Any suggestions?
P = 'absolute or relative path to where the files are saved'; S = dir(fullfile(P,'*.txt')); for k = 1:numel(S) F = fullfi...

4 years ago | 0

Answered
Did I do anything wrong when I used the "second" function?
"Did I do anything wrong when I used the "second" function?" Yes, you supplied the wrong input class: as its documentation clea...

4 years ago | 0

| accepted

Load more