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

Answered
Extracting values from array separated by zeros
V = [0,0,0,0,0,2,3,4,5,0,0,0,0,0,1,1,2,3,0,0,0,0,0,0,4,5,1,2,0,0,0,0]; D = diff([true,V==0,true]); B = find(D<0); E = find(D>...

4 years ago | 0

Answered
1D interpolation over vector of observations with linear extrapolation
The query points do not have to be scalar: interp1(grid, func, obs ,'linear','extrap')

4 years ago | 0

Answered
How to keep rows whose values follow a certain sequence?
Here is an old MATLAB trick that you can use, which still works today: https://blogs.mathworks.com/loren/2008/09/08/finding-pat...

4 years ago | 0

| accepted

Answered
Shortening if/elseif loop for value segregation
What you are doing can be broken into two parts: the first part is generally known as data binning. You can do data binning quit...

4 years ago | 1

| accepted

Answered
How do I multiply digits of a given number?
N = 12345; S = num2str(N); prod(S([1,3])-'0')

4 years ago | 0

Answered
my problem is about @.
f = @(x) x.^2; % ^ ^ you forgot these parentheses q = quad(f,1,2) How to define anonymous functions is explained here: ht...

4 years ago | 1

| accepted

Answered
How to automate .mat file loading
You can use the approaches shown in the documentation: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-o...

4 years ago | 0

| accepted

Load more