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')

4 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 =...

4 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...

4 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...

4 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...

4 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)*[...

4 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'; ...

4 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('...

4 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...

4 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...

4 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...

4 years ago | 0

| 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...

4 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]

4 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...

4 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",...

4 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...

4 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...

4 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))

4 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...

4 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...

4 years ago | 0

| accepted

Answered
How I can detection column indexes of string 'rk_accept_metaln' (n=1,2,3,4....)
C = {'X','Y','Z','X_size','Y_size','Z_size','volume','block_tonnage','rk_accept_grade1','rk_accept_metal1','rk_rejected_grade1',...

4 years ago | 0

| accepted

Answered
Compute the mean row cell elements in a cell array.
Where C is your cell array: fun = @(varargin)mean(cat(3,varargin{:}),3); D = cellfun(fun,C(1,:),C(2,:),C(3,:),'uni',0)

4 years ago | 1

| accepted

Answered
How to index array with an array?
u = [11,12,13;21,22,23;31,32,33] % Access element at row 2, column 1 id = [2,1] ic = num2cell(id); u(ic{:}) https://www.mat...

4 years ago | 0

| accepted

Answered
How to I call specific values from a 45x1 Matrix?
link_forces = solution([3,5,14,17,25,28]) See: https://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab...

4 years ago | 0

Answered
Assign a cell data that starts with a regular expression
Always LOAD into an output variable! That will make your code much more reliable, and makes this task easier. Method 1: the sim...

4 years ago | 0

| accepted

Answered
Removing zeros from matrix
A = [1,2,3,4,5,6;1,2,3,4,5,6;1,2,3,4,5,0;1,2,3,4,0,0;1,2,3,0,0,0] Method one: NONZEROS and CELLFUN baz = @(v)v(end); fnh = @(...

4 years ago | 2

| accepted

Answered
How to distribute elements of a vector to each of output variable?
You can use a comma-separated list: x = [1,2,3,4,5]; c = num2cell(x); [a,b,c,d,e] = c{:} https://www.mathworks.com/help/matl...

4 years ago | 0

Answered
Explain why it makes sense that matrix A( :, :, 1) is two-dimensions, while A( :, 1, :) and A(1, :, :) return three dimensions
So far no one has really answered why this makes sense, which is what the original question asked. "My question was more about ...

4 years ago | 0

Answered
Create loop to load .mat file and store values to a matrix.
This should get you started. In the absence of any data desription I assumed that withinin each file x and y are scalar. You wil...

4 years ago | 0

| accepted

Answered
Splitting a table using varagin
"The matlab documentation states that the first term in the bracket after splittaply should be a function such as @max" The SPL...

4 years ago | 0

| accepted

Load more