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

Answered
How to remove letters from cell arrays
Why do you need to delete them? >> str = '2019-08-20T13:58:31Z'; >> datevec(str,'yyyy-mm-ddTHH:MM:SS') ans = 2019 ...

7 years ago | 1

| accepted

Answered
How do I use nargin to differentiate between a default units setting and unit input from function call
Replace units = 'm'; with if nargin<4 units = 'm'; end

7 years ago | 0

| accepted

Answered
How to track elements in a matrix that switch their position when converting into another matrix?
>> A = [1,2,3,4,5,6,7,8,9,10;1,2,3,4,5,6,7,8,9,10]; >> B = [1,1,1,1,2,3,4,5,6,7;1,1,1,1,1,1,1,1,2,3]; >> C = [6,7,8,9,10,10,10...

7 years ago | 1

| accepted

Answered
Arrays exercise Maximum and Minimum values
>> B = nonzeros(A(:)); >> M = bsxfun(@minus,B,B.'); >> V = abs(M(~eye(numel(B)))); >> max(V) ans = 5 >> min(V) ans = 1

7 years ago | 0

Answered
row vector and column vector addition
"I should get an error right?" Not since R2016b: https://blogs.mathworks.com/loren/2016/10/24/matlab-arithmetic-expands-in-r20...

7 years ago | 3

| accepted

Answered
Sampling iteratively random value from a matrix/array
No loops required, just use indexing: k = 1:13; % fake data n = numel(k); rl = [0.7 0.8 0.85 0.95 1] rs = [0.65 0.7 0.75 0.8...

7 years ago | 1

| accepted

Answered
Confused with the switch-case outputs with nargin
"Why the function chooses the second case to execute?" Because that is exactly what you wrote your functions to do. You call b...

7 years ago | 1

Answered
k- in the Borders function written by Chad Greene
https://www.mathworks.com/help/matlab/ref/linespec.html 'k' black color '-' continuous line (i.e. not dots or dashes)

7 years ago | 0

| accepted

Answered
Error: The expression to the left of the equals sign is not a valid target for an assignment.
As Walter Roberson already wrote, the problem is most likely caused by unmatched curly braces or square brackets earlier in the ...

7 years ago | 1

| accepted

Answered
How to find out the value of a matrix corresponding row and column?
Use sub2ind: >> x = [1;2;3]; >> y = [1;1;2]; >> z = [0,4;5,6;1,0]; >> z(sub2ind(size(z),x,y)) ans = 0 5 0...

7 years ago | 2

| accepted

Answered
How do I see the variables in base workspace when I am in a function?
Method 3: dbup and dbdown.

7 years ago | 0

Answered
Audioplayer object not passed into callback function
The problem is your definition of the callback as a character vector: player.StartFcn = 'audiocallbacktest' Defining callbacks...

7 years ago | 2

| accepted

Answered
String Vector for-loop
>> str = {'a1','a2','a3','b1','b2','b3'}; >> vec = sscanf([str{:}],'%*[ab]%f',[1,Inf]) vec = 1 2 3 1 2 3 >> vec = str...

7 years ago | 0

| accepted

Answered
Calculate the number of nonzero rows
>> nnz(any(B,2)) ans = 2

7 years ago | 3

| accepted

Load more