Answered
If statement without loop
A = repmat(1:5,4,1) B = [3;2;1;5] C = A; C((1:5)>=B) = 0

5 years ago | 0

| accepted

Answered
date to string conversion
Ugh, do NOT use DATESTR. This is easier without using the old, imprecise, deprecated functions: aa = datetime('now','Format','d...

5 years ago | 1

| accepted

Answered
structure to a matrix
S = load('DD_hyde_iisc_0.3to6.3_15.mat') T = struct2table(S.DD_SlantSmoothTEC)

5 years ago | 1

| accepted

Answered
how to convert array of cells within array of cells in single cell array
A = {{[2,3,4]},{ [],[3,4],[3,8,13]},{[4,0]},{[9,4],[9,8,13],[],[9,14,19]}} B = [A{:}] https://www.mathworks.com/help/matlab/ma...

5 years ago | 0

Answered
Passing multiple Arrays to loop a Function and creating a 1 column array
Assuming that the function output is scalar: mmm = zeros(sz,1); for k = 1:sz mmm(k) = Function(HistoricalValue,A(k),C(k),...

5 years ago | 0

Answered
How do I cd inside a for loop to a bunch of folders containing a file with same name?
Do not change directory just to import/export data files. Use absolute/relative filepaths instead, it is more efficient and eas...

5 years ago | 1

| accepted

Answered
Import 3D matrix in .mat File
"Hi, I have a file 'data.mat' attached. The file contain a 3D matrix with 128x128x128 dimension." No, it does not. It actually ...

5 years ago | 0

| accepted

Answered
Load files with similar name
P = 'absolute or relative path to where the files are saved'; S = dir(fullfile(P,'user_*.csv')); for k = 1:numel(S) F = f...

5 years ago | 0

| accepted

Answered
Avoid using eval on loading struct from a file
"As using eval is not the optimal way, is there any other way to do this?" Always LOAD into an output variable (which is a scal...

5 years ago | 0

Answered
I'm newish to MATLAB and want to automate populating a matrix A rather than manually create...
TM = [0.1,0.1,0.1,0.1,0.1,0.2,0.3,0.4,0.6,0.8,1.0,1.0,1.0,1.0,1.0,0.8,0.6,0.4,0.2,0.1,0.0]; N = 4; M = toeplitz([TM(1),zeros(...

5 years ago | 0

| accepted

Answered
x=[1 2 3 4]y=[2 4 5 10]x1=[1,1.5,2.2,3.5,4] how to get previous matching value(from y) for x1 by refering x expected answer y1=[2 2 4 5 10] without forloop
x = [1,2,3,4]; y = [2,4,5,10]; x1 = [1,1.5,2.2,3.5,4]; %y1=[2,2,4,5,10]; y1 = interp1(x,y,x1,'previous')

5 years ago | 0

| accepted

Answered
read multiple channels of different amounts of data into single matrix
Assuming that all imported matrices have exactly the same number of columns in the same order: N = 10; C = cell(1,N) for ch =...

5 years ago | 0

| accepted

Answered
How to use strings to access a multi-level structure?
The variable name should not be dynamically accessed: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-varia...

5 years ago | 1

Answered
Corrupted Order of the Elements of struct.name After Using dir Function
For those filenames you can simply define the regular expression to include leading whitespace: C = {'100.jpg',' 99jpg'}; % che...

5 years ago | 0

Answered
Get data from each row as inputs to a function
N = numel(Strike); Volatility = cell(1,N); for k = 1:N Volatility{k} = impvbybjs(RateSpec,StockSpec,Settle,Maturity,Opt...

5 years ago | 0

Answered
Interpolation input grid is not a valid meshgrid
You mixed up the dimensions. This follows the explanation and examples in the INTERP2 documentation: omega = ((1/3.6)/0.0625)*[...

5 years ago | 0

| accepted

Answered
Read and process multiple sheets from Excel to Matlab
Untested, but this should get you started: P = 'absolute or relative path to where the files are saved'; F = 'filename.xlsx'; ...

5 years ago | 1

| accepted

Answered
Separating a CSV into multiple CSVs by an ID within the CSV, using that ID as the new filename
Most likely you only need one loop. Because you did not upload a sample file I had to create my own (attached): T = readtable('...

5 years ago | 1

| accepted

Answered
Pass structure variables one by one to a function (input) and name the outputs based on input names
The simple and efficient MATLAB approach is to use dynamic fieldnames and indexing: % Creating dummy data yData.a = rand(405,1...

5 years ago | 0

| accepted

Answered
textscan: strings and variables
Perhaps something like this, a more robust approach using a structure (this still requires that the headers are valid MATLAB nam...

5 years ago | 1

Answered
Convert time vector of Year, Month, Day, Hours, Minute to Decimal format
Simpler: format long G D = datetime(2019,10,(2:13).',12,0,0) B = dateshift(D, 'start', 'year'); % midnight at start of the ye...

5 years ago | 1

| accepted

Answered
Dynamically naming new table columns in a loop
"What's the secret?" Very simple: don't use EVAL. It is simpler, much more robust, and much more efficient to add fields using...

5 years ago | 0

| accepted

Answered
Convert numerical Matrix values into logical Matrix
A = [1,3,4,9,12;2,5,6,9,11;1,4,5,10,12] X = any((1:12)==permute(A,[1,3,2]),3) M = [1:12;+X]

5 years ago | 0

| accepted

Answered
Split cell each 13 characters
The better approach is to use READMATRIX or READTABLE with the fixed-wdith importing option: fnm = 'test.txt'; opt = detectImp...

5 years ago | 1

| accepted

Answered
How to use 'for' loop to string variable ?
Assuming that each file contains exactly one variable (itself a structure with the same field names): T = ["Battery_Power_280",...

5 years ago | 0

| accepted

Answered
How to determine if table format value is array or cell?
Summary: you need to use curly braces to refer to the content of a table. Explanation: tables are a container class: they are a...

5 years ago | 0

Answered
How to display a table without it showing "var1"?
Tables are a container class: they contain data of other classes. So it is very important to distinguish between the table itsel...

5 years ago | 0

| accepted

Answered
Using strjoin on each row of NxM cell array
C = {'ABC','123','blue';'DEF','456','red';'GHI','789','green'} D = cellfun(@(v)join(v,'_'),num2cell(C,2))

5 years ago | 1

| accepted

Answered
Assigning array values to cell array based on condition
A = [1,1,1,2,2,3,3,3,3]; B = [6,3,7,4,7,13,16,4,1]; C = accumarray(A(:),B(:),[],@(v){v}); C{:} For the second part of your q...

5 years ago | 0

| accepted

Answered
How to load multiple mat files from a folder in a sequence?
S = dir(fullfile(Folder, '*.mat')); for k = 1:numel(S) F = fullfile(Folder,S(k).name); % you need FOLDER here too. d...

5 years ago | 0

| accepted

Load more