Answered
how to Vectorize this for loop?
Well, the vectorised version of your code is to use |conv2|! Or |ifft2| the |fft2| product (with suitable padding). Otherwise...

9 years ago | 0

| accepted

Answered
Help converting Python to Matlab
I don't know Python but in most languages the % operator is either integer division or the modulo operator. A quick search revea...

9 years ago | 0

Answered
textscan loop works on windows but not on macOS - why?
To find out why |fopen| failed to open a file, change your script to: for i=1:length(files) [fid, errmsg]=fopen(files...

9 years ago | 0

| accepted

Answered
how do I pre-allocate the program. It highlights it in red and I am not able to do that. Thanks for helping.
Assuming your ODE returns a 3x3 array: v1sol = zeros(3, numel(rho) - 1); v2sol = zeros(3, numel(rho) - 1); v3sol = ze...

9 years ago | 0

Answered
Functions in a script file
It does not look like you understand how functions work. When you write function [totalA, totalB]=Cost(gallons, priceA, pri...

9 years ago | 0

| accepted

Answered
merge multiple 4-D double
Numbered variables are always a bad idea. Much better would be to just have one variable (a cell array in your case) containing ...

9 years ago | 0

| accepted

Answered
Error using fprintf, Invalid file identifier
Your code failed to open the file for writing. There can be many reasons for that which we can only take a guess at. Maybe the f...

9 years ago | 2

| accepted

Answered
can this loop be vectorized ?
Very simply with: freq = accumarray(A(:), 1, [256, 1]);

9 years ago | 0

| accepted

Answered
Adding zeros to a matrix to match the dimensions of two matrices.
newA = [A, zeros(size(A, 1), size(B, 2)-size(A, 2)); zeros(size(B, 1)-size(A, 1), size(B, 2))]; Assuming that both dimension...

9 years ago | 2

| accepted

Answered
Sum rows that have duplicate values in 2 other rows
Possibly a simpler method, using the newish <https://www.mathworks.com/help/matlab/ref/splitapply.html |splitapply|>: m = [...

9 years ago | 5

| accepted

Answered
randn function does not work
For some reason, my dice don't work either. I've thrown them many times, yet the mean value is not exactly 3.5. >> mean(rand...

9 years ago | 0

Solved


How to subtract?
*&plusmn &plusmn &plusmn &plusmn &plusmn &plusmn &plusmn &plusmn &plusmn &plusmn &plusmn* * Imagine you need to subtract one...

9 years ago

Answered
Identifying data from specific time periods
With so little information, it's difficult to go into details, but matlab has the function <https://www.mathworks.com/help/matla...

9 years ago | 0

Answered
How to create date vector with a specify start and end (for many periods using loop)
You would be better off using the modern <https://www.mathworks.com/help/matlab/ref/datetime.html |datetime|> rather than the ol...

9 years ago | 0

Answered
is there an xml parentNode property
Matlab uses Java classes for its implementation of the xml DOM. There is indeed a way to get the parent of a node with <https://...

9 years ago | 0

| accepted

Answered
How to call a figure but not bring it up on screen?
As Rik says, by far the best approach is to keep the handle of the figures and axis you create and pass these handles to your pl...

9 years ago | 0

Answered
How can i check if a matrix is magic square or not?
Refer to the definition of a <https://en.wikipedia.org/wiki/Magic_square magic square> and test for that, i.e. sum the rows, col...

9 years ago | 0

Answered
hello guys.....can someone help me with this??
Well, clearly your |fopen| call failed. It could be because the file does not exist in the current folder or you don't have perm...

9 years ago | 2

Answered
error with || and && operators in a while loop
I don't have the psychotoolbox, but have a look at the documentation of |kbCheck|. The reason you get an error is because the...

9 years ago | 1

| accepted

Answered
Is there a way to use a loop to split a 3D character array at specific location and store the new data into a Cell Array
Note that |cellstr| wouldn't give you a 2x2 cell array but a 15x2x2 cell array. You could obtain that with: mat2cell(Data, ...

9 years ago | 0

Answered
Can I define a structure iteratively?
It's not very clear what you're trying to achieve. As it is you're always creating the same field always called |'field_i'|. You...

9 years ago | 0

Answered
Calculation Pixel In range
Assuming that your image is of class |double|, then sum(yourimage(yourimage >= 1000 & yourimage <= 30000))) _EDIT: As Im...

9 years ago | 0

| accepted

Answered
How to know whether it is an image or a website with a given url?
The way matlab (or any other web client) determine the type content of a uri is by looking at the |Content-Type| property return...

9 years ago | 1

| accepted

Answered
how to calculate the total number of pixels in a user selected region i.e rectangle??
It looks like you're not familiar with <https://en.wikipedia.org/wiki/Scientific_notation scientific notation>. 2.1583e4 and 215...

9 years ago | 0

| accepted

Answered
i have A=[ 1 3 5 7] B=[2 4 6 8] i need to get answer like c=[1 2 3 4 5 6 7 8] pl help me
c = reshape([A; B], 1, []) would be one way.

9 years ago | 1

Answered
How do you write comments in sub functions?
It's not exactly clear what you are calling subfunctions. I'm going to assume that you mean either a <https://www.mathworks.com...

9 years ago | 0

Answered
Difference between num2cell(1:4)' and {'1','2','3','4'}' ?
The simplest way to convert numbers to strings or char arrays since R2016b is: string(1:15) %that's it! In earlier vers...

9 years ago | 0

| accepted

Answered
How to do xor operation in cell arrays?
If you start with a cell array of hexadecimal char arrays and want the same back: cellfun(@(a,b) dec2hex(bitxor(hex2dec(a),...

9 years ago | 0

| accepted

Answered
How to solve this index exceeds matrix dimensions error?
As you've stated |X| is a Nx1 vector. Yet, you have: X(i, j) X(i, 2) X(i, N) in your code. How are you expecting t...

9 years ago | 0

Load more