Answered
How do I use a variable (say "i", as in for i=1:10), as part of a variable name?
The MATLAB documentation recommends using a cell array (being much simpler and more efficient than what you are attempting to do...

6 years ago | 0

Answered
workaround for handling a large number of variables in the objective function of lsqnonlin
>> X = rand(7,3); >> w = rand(3,1); >> w(1)*X(:,1) + w(2)*X(:,2) + w(3)*X(:,3) % what you do now ans = 0.63892 0.4308...

6 years ago | 1

| accepted

Answered
how can i avoid the for loop in this case?
Method one: logical equals: >> a = [3,6,7,8]; >> V = 1:10; >> M = double(V(:)==a) % requires MATLAB >= R2016b M = 0 0 ...

6 years ago | 0

| accepted

Answered
How to combine the result of for loop?
>> A = 1:3; >> repelem(A,1,A) ans = 1 2 2 3 3 3

6 years ago | 0

| accepted

Answered
Dot indexing is not supported for variables of this type
You used the same name for two different variables: Change the name of the serial link variable to something else. You will n...

6 years ago | 0

| accepted

Answered
Function to format number as currency?
Just one simple Python call: num = 98765432.1; str = char(py.locale.currency(num, pyargs('grouping',py.True))) Or alternative...

6 years ago | 4

Answered
Using switch case to rename files in a folder
Method one: datetime scalar: Before the loop, define both the step size and the first time: >> step = minutes(10); >> first ...

6 years ago | 0

| accepted

Answered
plotting functions in matlab
function [y] = myfunction(theta) % "/" is not valid in a variable name y = sin(theta); end

6 years ago | 0

| accepted

Answered
i have a docuemnt with lots of numbers and i want to remove them for textanlaytics
str = fileread(...); str = regexprep(str,'\d+m?','');

6 years ago | 0

Answered
Index in position 1 exceeds array bounds (must not exceed 1818)
"What does "Index in position 1 exceeds array bounds" mean?" Here are the index positions for subscript indexing: anyarray(pos...

6 years ago | 0

Answered
Sometimes i sum the variable equal to 1. But when check the sum value, the logic is not correct. for example, P_SE = [0.5 0.2 0.2 0.1]. And, check sum(P_SE) == 1 but the logic shows 0. How can I fix this problem?
"...the logic is not correct..." The logic is correct: those values do NOT sum to exactly one. Neither of 0.1 nor 0.2 can be re...

6 years ago | 0

Answered
Sort variables form lowest to largest but by keeping their name
Using separate variables is an approach that will force you into writing slow, inefficient, complex code. A much better use of M...

6 years ago | 0

Answered
What exactly is this 3D object inside my axis and how to attach it to a colormap?
That figure contains four objects, the fourth one listed is the main axes: >> fgh = openfig('Resultplot_ID3.fig'); >> fgh.Chil...

6 years ago | 0

| accepted

Answered
What the difference between using bracket and not.
None of the answers explain why this works, nor even mentioned the useful-to-know name of this syntax. The actual reason is bec...

6 years ago | 5

| accepted

Answered
Create a 1 x m Structure instead of a 1x1 Structure
S = struct('FirstField',num2cell(1:100), 'SecondField',num2cell(1:100))

6 years ago | 2

| accepted

Answered
Function implementation in matlab
>> a = 0.9; >> V = 0:40; >> M = a.^(V+V(:)); % requires >=R2016b For earlier versions replace the + with bsxfun.

6 years ago | 0

Answered
How to find all the combinations of a vector elements whose sum is equal to a given number
A simple recursive nested function, with short-circuiting for combinations whose sums are greater than N (this makes the whole t...

6 years ago | 0

| accepted

Answered
Sum and Difference across row and column
>> sum(A(:,2))-A(2,1)-A(2,3) ans = -0.19880

6 years ago | 0

| accepted

Answered
how r to each Matlab folder
cd :\E % incorrect (what you wrote) cd E:\ % correct (what you should do)

6 years ago | 0

| accepted

Answered
How does clearing nested function workspace works?
I have use nested functions extensively for many years, and have also been curious about this behavior. As far as I have found, ...

6 years ago | 1

| accepted

Answered
showing unit using fprintf
fprintf and sprintf do not generate formatted text based on markup (like LaTeX or XML). Their output is pure text, and pure text...

6 years ago | 0

| accepted

Answered
sprintf naming of figures
The closing parenthesis is in the wrong place: sprintf('S10_AHAPlot_%s_%s_%s_R%u.fig', order(k), orderS(y)), Observer, Rep; % w...

6 years ago | 0

| accepted

Answered
How to assign values to a column in each row where the column number for each row is specified in a vector?
Use sub2ind like this: >> A = zeros(2,2); >> idc = [2,1]; >> idx = sub2ind(size(A),1:numel(idc),idc); >> A(idx) = 1 A = ...

6 years ago | 0

| accepted

Answered
CSVread / dlmread not working when trying to upload a CSV file
The csvread documentation explains that the 2nd, 3rd, 4th and 5th input arguments are an offset value, and that they must be spe...

6 years ago | 0

| accepted

Answered
how does a function invoke the inputs?
MATLAB's function input and output arguments are entirely positional. Their names are irrelevant. When calling a function, you ...

6 years ago | 0

| accepted

Answered
Eliminate solutions that are a subset of another
"I am sure this has a simple solution but I can't seem to determine it." Here is one simple solution that passes your example: ...

6 years ago | 0

Answered
How can you read a filename but store a specific number within it?
D = 'path to the folder where the files are saved'; S = dir(fullfile(D,'*crop*area*.jpg')); [~,N] = cellfun(@fileparts,{S.name...

6 years ago | 1

| accepted

Answered
Find a word in a file then pick the value next to it
>> str = fileread('test.txt'); >> rgx = 'MAX_ANCRAGE_[XYZ]_(?:6881|6952|6968),\s+(\d+\.?\d*)'; >> tkn = regexp(str,rgx,'tokens...

6 years ago | 1

Answered
Is it case sensitive?

6 years ago | 1

| accepted

Answered
double summation of a matrix
By far the easiest solution is to use conv2, e.g. where S is your array: >> S = randi(255,330,332,'uint8'); >> U = conv2(doubl...

6 years ago | 0

Load more