Answered
How to separate a portion of filename from a file
Simpler: >> str = 'scrubbed.MOD_D3_AOD_550.20020112.nc'; >> out = regexp(str,'\d{8}','match','once') out = 20020112

7 years ago | 1

Answered
Only add to empty elements in an array
>> d = cat(3,a,b,c); >> sum(d.*(cumsum(d~=0,3)==1),3) ans = 1 2 3 4 5 6 7 8 9

7 years ago | 0

| accepted

Answered
Function returning ans instead of three outputs
You need to call the function with three output arguments, e.g.: inp = [...]; % your input array [RR,GG,BB] = MostDistantPixel...

7 years ago | 1

| accepted

Answered
Creating a stacked bar plot
The bar documentation states "If y is a matrix, then bar groups the bars according to the rows in y", so you need to translate y...

7 years ago | 4

| accepted

Answered
Assigning RGB values to a new 3D RGB image
staticImage(i,j,:) = [R,G,B];

7 years ago | 0

| accepted

Answered
Converting columns in a matrix to percentage
>> M = [48,40,35,52,38,11,64,39,26;50,35,37,55,43,24,54,25,26;33,27,36,28,26,27,39,27,16;40,29,40,51,29,24,47,32,29;66,37,38,51,...

7 years ago | 0

| accepted

Answered
How can I create cell arrays that are in sequential order?
Two simple solutions: add sufficient leading zeros to all of the numbers (then a character sort will give the correct order). T...

7 years ago | 1

Answered
Read a specified list of images given the filename and the directory the files are in
D = "path of the directory where the images are saved"; S = ["string array","of","the image filenames"]; N = numel(S); C = ce...

7 years ago | 0

Answered
How to index tables in a struct? (to call each field from App Designer)
You need to loop over the fieldnames: app.data = load('workspace.mat'); C = fieldnames(app.data); for k = 1:numel(C) T =...

7 years ago | 0

| accepted

Answered
How to index so end+1 goes to the beginning of an array
>> V = 1:4; >> V(1+mod((end+1)-1,end)) ans = 1 >> V(1+mod((end+0)-1,end)) ans = 4 >> V(1+mod((end-1)-1,end)) a...

7 years ago | 0

| accepted

Answered
Is it possible to organize variables shown in workspace?
"At the end of simulation are variables of two scripts are shown in workspace alphabetically. Is it possible to sort them by scr...

7 years ago | 0

Answered
What do the empty square brackets [] do in the expression executed by eval?
"What do the empty square brackets [] do in the expression executed by eval?" Nothing really. MATLAB has positional input argu...

7 years ago | 0

| accepted

Answered
How can I work around the fact that app designer does not support output arguments?
https://www.mathworks.com/matlabcentral/answers/707338-output-arguments-in-app-designer

7 years ago | 0

| accepted

Answered
Fill an array with different size vectors
For an arbitrary number of vectors use a cell array, then looping is trivial: >> D = {[1,2,3,4],[5,6],[7,8,9]}; >> M = zeros(5...

7 years ago | 1

| accepted

Answered
calling a matrix with different names in a for loop
Simply put your three matrices into one cell array, then your task is trivial: C = {NPV_1, NPV2, NPV_3}; for k = 1:numel(C) ...

7 years ago | 1

| accepted

Answered
Subscript indices must either be real positive integers or logicals.
It is much simpler to iterate over indices, than iterating over data values. So rather than this: for t = 1:5 % iterate over da...

7 years ago | 0

Answered
using f(end)
When used as an index, end returns the last index (for the specific dimension, or as a linear index). Because f is defined as a...

7 years ago | 0

Answered
Help with searching for a specific input filetype within a directory
F = '.jpeg' S = dir(['*',F])

7 years ago | 1

| accepted

Answered
what is the error in this program
k = 5:5:50; Pr1 = (10*0.75*0.75*(exp(-0.984*k./cos(pi/36))) .* 0.01 .* cos(pi/36) ./ ((2*pi*k.^2)*(1-cos(pi/3)))); z=10.*log10...

7 years ago | 0

| accepted

Answered
How to get vectors of common duplicates in a cell array?
>> [~,~,X] = unique(A); >> [B,Y] = hist(X,1:max(X)); >> C = arrayfun(@(y)find(X==y),Y(B>1),'uni',0); >> C{:} ans = 1 5 ...

7 years ago | 0

| accepted

Answered
Run a code multiple times in different directories
"but it has a problem for openning and running the .m file in the folder, any idea??" Your code opens a text file, and then clo...

7 years ago | 0

Answered
Basic Math Calculation and Equation
>> fun = @(x) x.^x - 5.^x; >> x = fzero(@(x)fun(x)-0.0237,pi) x = 5.000007583872926 >> fun(x) % checking ans = 0.02370000001...

7 years ago | 1

| accepted

Answered
Dealing with wrong input
str = ''; num = NaN; while isnan(num) num = str2double(input([str,'Enter a number: '],'s')); str = 'Please try again...

7 years ago | 0

Answered
Problem calling multiple files through for-loop
The problem is caused by badly designed .mat files, where every .mat file contains variables with different names. Your code ass...

7 years ago | 0

| accepted

Answered
Don't understand what 's' is
The input documentation describes the effect of its second optional input argument as "str = input(prompt,'s') returns the enter...

7 years ago | 0

| accepted

Answered
Matrix problem for same values of column
N = size(A,1); X = ones(N,1); % group numbers Z = true(N,1); % logical index V = 1; % group number for k = 2:N % for each ro...

7 years ago | 0

| accepted

Answered
How can I have a starting number, a step size, then the number of numbers I need in a 1D array?
>> A = 5; % starting number >> S = 3; % step >> N = 12; % number of values >> V = A+S*(0:N-1) V = 5 8 11 14 17 20 2...

7 years ago | 2

| accepted

Answered
How to save data from a for loop?
Where T is your table: for k = ... T = your table F = sprintf('Results_%d.txt',k); writetable(T,F) end

7 years ago | 0

| accepted

Answered
How to find index with findpeaks?
findpeaks has a second output argument with the indices: [A,idx] = findpeaks(...)

7 years ago | 0

| accepted

Answered
How to select data from a cell array based on some condition
>> A = {[0,5], [-2,3]; [0,0], [12,-21]}; >> B = cellfun(@(v)v(v>2),A,'Uni',0); >> B(cellfun('isempty',B)) = {NaN} B = [...

7 years ago | 1

| accepted

Load more