Answered
Extract numbers from an integer
N = 123411; noOfOnes = nnz((dec2base(N,10) - '0')==1);

8 years ago | 0

Answered
Intersecting a curve and a line
There is a FEX submission called curveintersections, find it on the below link: <http://de.mathworks.com/matlabcentral/fileex...

8 years ago | 0

Answered
Export variables of for loop into an excel sheet
You probably want to store your loop iterations in an array. A = zeros(1,10); %pre-allocate for k=1:size(A,2) %use A's si...

8 years ago | 0

Answered
How to set a column element from a text array in uitable GUI
Put all your table data in a cell array and then update them, not just one column. data = {'John',12;'Kevin',46;'Steffi,23};...

8 years ago | 0

| accepted

Answered
How can Write a function that combines two lists by alternatingly taking elements, e.g. [23,11,70], [1,2,3] → [23,1,11,2,70,3].
No need to use a loop, A = [1 2 3 4 5]; >> B = 10*A; >> C = zeros(size([A B])); >> C(1:2:end) = A; >> C(2:2:end...

8 years ago | 0

Answered
how can I add add sec, min and hours to time?
Use duration maybe, <https://www.mathworks.com/help/matlab/ref/duration.html> >> t1 = duration([07 0 0]) t1 = ...

8 years ago | 1

Answered
How can I write a script to calculate conditional probability from a user created 2 way table
Maybe something like this? r = input(['Please enter the choice of row for conditional probabilty (between 1 to ' num2str(nu...

8 years ago | 0

| accepted

Answered
how to substitute a variable in function
You need to learn about how matlab workspaces work. <https://www.mathworks.com/help/matlab/matlab_prog/base-and-function-work...

8 years ago | 0

| accepted

Answered
How would i make the for loop stop calculating when it calculates F <= 0? I want the for loop to stop writing. values in F when it hits 0 or less. I have tried "break", but can not seem to get it to work.
You should simply check F(k), inside your loop, for k = 3:n r = rand(1); if r > terskelverdi F(k) = F(k-...

8 years ago | 0

| accepted

Answered
Setting up vector function
c = -k(2:end); %EDITED d = k+[k(2:end);0]; e = c; in case, k is row vector, c = -k(2:end); %EDITED d = k+[k(2:e...

8 years ago | 2

Answered
read number put them in array, remove line , and store them in new file?
Do it with dlmread and dlmwrite, <https://www.mathworks.com/help/matlab/ref/dlmread.html> <https://www.mathworks.com/help/...

8 years ago | 1

| accepted

Answered
how to sort this looping ?
Rik is right, logical indexing will make it lot simpler and faster, wmin = 0.4; wmax = 1.2; it= 1:1000; then pre-all...

8 years ago | 0

| accepted

Answered
How to make a character array from loop output?
store them in a cell array, seq = cell(1,9); for m = 1:9 k(m) = randi([4,6],1); seq{m} = randseq(k(m) ,'Alphabet...

8 years ago | 0

| accepted

Answered
Search array for largest value of the desired format
Something like, A = [1 2 1000 3 4 2000 4 3 3000]; B = (1:10)*1000; res = nnz(ismember(A,B)); and if there are more t...

8 years ago | 0

| accepted

Answered
Dimensional problem in for loop.
*EDITED* First you should make sure if loop is required at all in the first place, if yes then I would suggest linear indexin...

8 years ago | 1

| accepted

Answered
Writing a script to create a table based on user input with row names and columns
Do it like this, row = input('Enter number of rows: '); col = input('Enter number of columns: '); A = zeros(row,col);...

8 years ago | 0

| accepted

Answered
How can I get the sum of rows and columns of a table and add them to the table?
After you get the row and col values from the user, pre-allocate it by, A = zeros(row+1,col+1); I say "+1" because that'S...

8 years ago | 1

| accepted

Answered
Storing vectors for different time steps in same variable name
Why don't you use a matrix? Let's say you have 10 timesteps (1 to 10), ts = 1:10; so now you'll need to track A's chan...

8 years ago | 0

| accepted

Answered
How to load specific files according to vector values?
Something like this? for k = 1:10 data = load([num2str(ii(k)) '.mat']); dataStruct(k).file=data.Cycle; end

8 years ago | 0

Answered
How to reshape data?
If you're using 2016b or later, please use a timetable. Then you can simply call retime to make monthly averages, TT_monthly...

8 years ago | 0

| accepted

Answered
comparing two matrix of different size
ismember(A,B)

8 years ago | 1

Answered
Finding the values right after and right before some values in a matrix
res = find(V>A(1,1) & V<A(2,1)) for all elements, res = arrayfun(@(x,y) find(V>x & V<y), A(1:end-1,1), A(2:end,1),'uni',...

8 years ago | 0

Answered
how to include n = 1:25; power = 1:4:100; cg = 1:6:150; in single expression using for loop
Do you really need a for loop? Check this, n = 1:25; power = 1:4:100; cg = 1:6:150; b=1; noise = rand(size(...

8 years ago | 0

Answered
How to extract all the rows which match an specific string column
Use readtable to import your data, T = readtable('DatosEstructurales_C&S.txt'); if you don't have column names included ...

8 years ago | 4

Answered
If the input is 3 we want the output to be 1 2 1
Shouldn't it be just, >> n = 7; >> weights = [1:ceil(n/2) floor(n/2):-1:1] weights = 1 2 3 4 3 2 1

8 years ago | 0

| accepted

Answered
how can I add a value to a particular cell in an array.
if A is your array, >> A = [3,2,4,5;3,2,6,4;2,5,8,5] A = 3 2 4 5 3 2 6 4 2 5 8 5...

8 years ago | 0

| accepted

Answered
How can variables in workspace be used in Simulink function
One idea is to take it as an input to your function block and use the "constant block". Your function could look like, ...

8 years ago | 0

Answered
Take date month year from serial date numbers data
if you have something like, >> dt = datetime([2017 11 06 08 00 00]) dt = datetime 2017-11-06 ...

8 years ago | 0

Answered
How to use color code say [0.1 0.5 0.6] in patch and fill command?
remove the quotes fill (x,y, [0.5 0.3 0.6]); you need to pass a 3x1 vector, not a string.

8 years ago | 1

Answered
How to export mulitple 1xN row matrix into the csv
Just create a table and use write table, t = array2table([A.', B.']); writetable(t,filename); or concatenate them and u...

8 years ago | 0

Load more