Answered
How I can extract data from a vector based on index
A simple and efficient approach: A = [5,3,7,8,89,6]; index = [2,3,4,5]; B = A; B(index) = []

4 years ago | 1

Answered
Concatenation of multiple matfile into one matfile
Assuming that each .mat file contains only one variable of unknown name: P = 'absolute or relative path to where the files are ...

4 years ago | 0

| accepted

Answered
Importing code from octave to matlab
tmp = abs(fft(c)); z = tmp(1:T*fs/2)/(T*fs);

4 years ago | 1

| accepted

Answered
How to repeat a prompt until a expected number is written by the user
A = 0; while ~ismember(A,1:4) A = input(..); end

4 years ago | 0

| accepted

Answered
Using readtable() for Excel file where only one column has mixed numbers and text
Of course you can specify the class, the simplest approach is probably via DETECTIMPORTOPTIONS and SETVARTYPE: fnm = 'filename....

4 years ago | 0

| accepted

Answered
How can I round a number to the higher whole number?
ceil(1.234) ceil(3.534)

4 years ago | 1

| accepted

Answered
Use strcmp() based on part of the row name in structure
Use https://www.mathworks.com/help/matlab/ref/endswith.html

4 years ago | 0

| accepted

Answered
How do I convert a vector into an Nx1 cell array of varying-length vectors?
Simpler: V = [1,2,3,4,5,6,7,8,9,10]; N = 3; L = numel(V); S = N*ones(1,ceil(L/N)); S(end) = 1+rem(L-1,N); C = mat2cell(V...

4 years ago | 0

Answered
Cell arrays into excel
Where C is your cell array: F = 'myfile.xlsx'; for k = 1:size(C,2) T = C{1,k}; M = C{2,k}; writematrix(M, F, 'S...

4 years ago | 1

| accepted

Answered
Line number in code
mytest() function mytest() % A = 1; B = 2; % F = @(s)s(1); % helper function % fprintf('%3u %s\n',F(dbstack()).line, 'he...

4 years ago | 0

| accepted

Answered
Remove equal sign and quotation marks in readtable
This should get you started. Note that you can tailor the range, etc. fnm = 'iv1_gdp_cum.csv'; opt = {'Delimiter',{',','='}, '...

4 years ago | 1

| accepted

Answered
Compact way to horizontally concatenate a cell array without the first columns of the cells
It rather depends on what you mean by "compact". C = {[2,4,6;1,3,8;6,9,1;6,1,1;5,5,2;3,7,8;9,2,4],[8,3,5;9,9,5;6,3,1;7,1,2;4,8,...

4 years ago | 0

| accepted

Answered
Combining two or more elements of vectors into 1
In MATLAB binary data is normally stored as character (see BIN2DEC, DEC2BIN, etc.). Perhaps STRING suits your needs (it gives e...

4 years ago | 0

Answered
How to extract numbers either side of a decimal place
The venerable NONZEROS could be used very effectively here: X = [1;2;3;4;5.4700;6;7;8;9.4100;10;11;12;13;14;15;16.4200]; X2 = ...

4 years ago | 1

Answered
Converting table column of cell arrays to column with comma separated values
A = [11;22;33;44;55]; B = {{'1'};{'2';'3';'4'};[];{'6';'7'};{'8'}}; T = table(A,B) X = ~cellfun(@isempty,T.B); T.B(X) = cell...

4 years ago | 0

| accepted

Answered
Import and process files from different folders in a loop
S = dir('C:/Users/Someone/Desktop/BlaBla/**/Output/file.txt'); for k = 1:numel(S) F = fullfile(S(k).folder,S(k).name); ...

4 years ago | 0

| accepted

Answered
Compact way to write matrices containing indices
A = [3;4;9;1;5]; B = [3,5;6,2;4,8;5,7;9,7]; [X,Y] = ismember(A,B(:,1)); M = A; M(:,2) = NaN; M(X,2) = B(Y(X),2)

4 years ago | 0

| accepted

Answered
Why is there aditional data loaded
" But this script is literally close everything and load the data into the workspace and it does all the extra stuff." No "extr...

4 years ago | 0

Answered
How to Extract Numbers after a particular String from a cell in Matlab
S = load('raw.mat'); raw = S.raw Method one: F = @(t)sscanf(t,'Rmin%f_Ymin%f',[1,2]); C = cellfun(F,raw(2:end,1),'uni',0); ...

4 years ago | 1

| accepted

Answered
Removing the space between %2d in a string statement.
Replace %2d with %d

4 years ago | 0

Answered
Put values from an array in a while loop into a table
There is no need to create lots of separate vectors, doing so would be very inefficient. Much simpler to convert the matrix usi...

4 years ago | 0

| accepted

Answered
interpulation of 2 axes in 3D matrix
format compact L = cat(3,[1,3,5;7,9,11;13,15,17],[3,5,7;9,11,13;15,17,19]) Xi = 1:3; Yi = [1,3,5]; Zi = [1,3]; [Xq,Yq,Zq] =...

4 years ago | 0

Answered
How to fill empty matrix elements based on surrounding values
V = [1;0;0;0;5;0;0;0;0;0;8;0;3]; The new approach: Z = fillmissing(V + 0./(V~=0), 'linear', 1) The old approach (repeat for e...

4 years ago | 0

| accepted

Answered
how to read a table and multiply its elements with eachother and store it in another table
If all you need are numeric operations across all columns then storing the data in one numeric matrix would make your task much ...

4 years ago | 0

Answered
Output names for splitEachLabel() in a for loop
"For this example, I am trying to end up with 10 new imageDataStores, trainImgs1, trainImgs2,...,testImgs1, testImgs2,...,testIm...

4 years ago | 0

| accepted

Answered
How to use multiple set of variables in a calculation and store the results?
Your current approach should be avoided: in general it is not considered good code design to store lots of data in executable co...

4 years ago | 1

| accepted

Answered
How to write to a .xlsx file and include a variable value in its filename
Of course, just use SPRINTF just as the documentation shows: https://www.mathworks.com/help/matlab/import_export/process-a-sequ...

4 years ago | 0

| accepted

Answered
Reshape a 2D Matrix to 3D in a block/tile wise manner and back(!)
Q1: "Can I do that only using reshape?" No, the order of the elements is different, so RESHAPE alone is insufficient (note that...

4 years ago | 0

| accepted

Answered
How to create a loop to add matrix columns?
The best approach is to avoid the need to write such bad code. The most important steps are: use a more suitable importing func...

4 years ago | 1

Answered
Extract only some specific elements of the arrays of a cell
C = arrayfun(@(n)num2cell(rand(1,5)),1:5,'uni',0) C{:} X = [2,5,1]; D = cellfun(@(d)d(X),C(X),'uni',0) D{:}

4 years ago | 0

| accepted

Load more