Risposto
Move and swap elements between vectors using loops and functions?
Vague question → vague answer: % swap at position k k = 3 c = A(k) A(k) = B(k) B(k) = c

circa 8 anni fa | 0

| accettato

Risposto
How to plot a filled box?
Plot each of the sides separately h = fill3([1 1 2 2],[1 2 2 1],[1 1 1 1],'r', ... [1 1 2 2],[1 2 2 1],[2 2 2 2],'r', ....

circa 8 anni fa | 1

| accettato

Risposto
Cumulative Sum for Column of Ones and Zeros
A perfect job for *runindex*: A = [0 1 1 1 0 0 1 1 1 1 0 0 0 1 1 1 1 1 1 0] B = runindex(A) B(A==0) = 0 My functio...

circa 8 anni fa | 2

| accettato

Risposto
Row vector and corresponding column vector for each row
Something like this? % two cell arrays (being column vectors) of strings c1 = {'hello', 'friend'} c2 = {'my' ; 'name'...

circa 8 anni fa | 0

Risposto
I need to write a function to calculate the maximum row sum of a matrix A using a for loop
To get you started current_max = -Inf ; current_max_rowindex = 0; for row_index = 1:size(A,1) row_sum = A(row_in...

circa 8 anni fa | 1

Risposto
Using Cell Arrays to Store a Matrix Each Time Through a Loop
You have multiple iterations using an iterator *i* ... I suggest to use more descriptive variable names :D

circa 8 anni fa | 0

| accettato

Risposto
Subscript indices must either be real positive integers or logicals.
run the script using the *debugger*, and check the contents of the variables when the error occurs >> dbstop on error % or ...

circa 8 anni fa | 0

Risposto
How to convert a folder with multiple type of images such as PNG, GiF, JEPG,...etc into JPG and store the converted images in a folder in desktop ?
Why not use a *dedicated* tool to convert images, like good-old IrfanView (does it still exist?) or gimp?

circa 8 anni fa | 0

Risposto
shift values in an array systematically
Here is one way: x = 1:320 ; dp = 40 ; v11 = repmat(11,1,7) ; c = arrayfun(@(k) [x(k:min(k+39,end)) v11], 1:dp:...

circa 8 anni fa | 1

| accettato

Risposto
Save struct indexed name as a variable
You can use FIELDNAMES: FN = fieldnames(stock.TimeSeries_Daily_) % process these names in more common date formats using...

circa 8 anni fa | 0

| accettato

Risposto
How do i remove rows that have a blank space in a cell array?
tf = cellfun(@isempty, C_email) % check each cell of the cell array holding the emails C_people(tf) = [] % remove the cell...

circa 8 anni fa | 0

Risposto
mat ops to locate values and place into new matrix
b = sort(a.*(a==9), 2, 'descend')

oltre 8 anni fa | 0

Risposto
FIND command returns empty matrix using ==
Replace _A==B_ with _abs(A-B)<Tol_, where Tol is a value reflecting what difference between A and B should be considered equal. ...

oltre 8 anni fa | 0

Risposto
How do you crop a Matrix?
You mean the number of dimensions of M is unknown, but Nkeep is known? Use subsref: M = randi(10,4,3,4,5) ; % arbitrary dim...

oltre 8 anni fa | 3

Risposto
How to find the first instance of a pattern in a cell array?
It would be much easier if you store this as regular arrays, rather then cell arrays of scalar cells. You can use strfind if all...

oltre 8 anni fa | 0

Risposto
Uniqueness of values in rows and columns of an array??
An arrangement of unique values in each row and column is known as a Latin Square. For each set of N distinct values there are a...

oltre 8 anni fa | 0

Inviato


latsq(N)
Latin Square Matrix

oltre 8 anni fa | 1 download |

5.0 / 5
Thumbnail

Risposto
How can I equalize the size of all arrays in a cell array?
You want to pad the shorter arrays with zeros? Q_Vic1 = {[1 2 3], [1 2], [1 2 3 4]} ML = max(cellfun(@numel, Q_Vic1)) ...

oltre 8 anni fa | 0

| accettato

Risposto
All combinations of binary matrix
G = [1 0 0 0 0 1 1; 0 1 0 0 1 0 1; 0 0 1 0 1 1 0; 0 0 0 1 1 1 1] C = permn([0 1],size(G,1)) R = C * G PERMN can be d...

oltre 8 anni fa | 0

Risposto
Convert color to value
So you have combinations of red and blue colour values (R,B) that correspond to a some arbitrary single values V according to th...

oltre 8 anni fa | 0

| accettato

Risposto
generate vector from fixed point
interp1 is your friend. An example: x = [0 4 7 10] y = (x-5).^2 xx = linspace(0,10,13) yy0 = interp1(x,y,xx) % d...

oltre 8 anni fa | 0

Risposto
Show All Possible Combination and Max. Value
Here is my approach to the first step (getting the sum of all combinations) % step 0, create a small fake data set A = r...

oltre 8 anni fa | 0

| accettato

Risposto
How EFFICIENTLY to extract multiple column base on multiple condition
Why not simply use direct indexing? r = s.c2(:, s.state)

oltre 8 anni fa | 1

Risposto
sum all combinations of 2d array
And another, faster, solution: a = [1,2,3,4; 5,6,7,8; 9,10,11,12; 13,14,15,16]; % data c = mat2cell(a,size(a,1),ones(1,s...

oltre 8 anni fa | 0

Risposto
sum all combinations of 2d array
a = [1,2,3,4; 5,6,7,8; 9,10,11,12; 13,14,15,16]; % data [n,m] = size(a) ; c = permn(1:m, n) ; % get all permutations of...

oltre 8 anni fa | 0

Risposto
Once more... Avoid global variable!
Take a look at the setappdata and getappdata. You can use the root handle to store variables. setappdata(0,'MyVar',1:10) ...

oltre 8 anni fa | 0

Risposto
How to prevent adding a number to a matrix elements?
Many, if not all, functions rely on scalar expansion to happen for the plus operator. I strongly suggest you either get used to ...

oltre 8 anni fa | 1

Risposto
Creating a script that finds all triple of the Pythagorean theorem.
ab = nchoosek(1:50,2) ; % all unique combinations of values c = sqrt(sum(ab.^2,2)) ; % hypothenuse tf = c == fix(c) & ...

oltre 8 anni fa | 5

Risposto
Find zeros in a part of a matrix
temp = Tarr(5:5:end,2:end) ; % get the relevant portion temp(temp==0) == 12345 ; % your value Tarr(5:5:end,2:end) ...

oltre 8 anni fa | 0

| accettato

Risposto
Improving speed using logical indexing vectorisation of a 3d array
So, let's see if I understood you correctly: * A is an m-by-n-by-3 array to begin with * If A(i,j,1) is less then 0, the thr...

oltre 8 anni fa | 0

Carica altro