Why the MATLAB auto converts variable into Matrix?
The following code generates (3x1) Matrix of Profit variable. How to get a single answer (value) from the Profit function?
for j =1:56
b = 20 ;
c1 = 30 ;
Qt = 100;
Profit = ( (Qt^2*(b  c1))/(b + c1)^3  (Qt*c1*l1)/(b + c1)^2  (2*Qt^2*b*c1*l2)/(b + c1)^3);
end for
The above code output the following answer:
Profit =
6.1929
6.1926
6.1924
1 answer

Problem resolved.
l2 and l1 in the program was 3x1 matrix. This why I was getting 3x1 as the answer.
See also questions close to this topic

How to set uniform brightness and contrass for different image?
I have a lot of images exactly 360 images with different brightness, can you help me how to set brightness so all of images have same brightness. Im using matlab for image processing.

What is the Eigen equivalent of Matlab repelem?
In Matlab, there is both repmat and repelem. For matrices
x1
andx2
of sizes[d, n1]
and[d, n2]
, you can do this in Matlab:n1 = size(x1, 2); n2 = size(x2, 2); M = repmat(x1, 1, n2)  repelem(x2, 1, n1);
What is the equivalent Eigen code? Below are two variants that I am not quite satisfied with. Variant 2 is almost as fast (with O3) as the Matlab implementation, but I wonder if it could be made into a faster oneliner?
int d = x1.rows(); int n1 = x1.cols(); int n2 = x2.cols(); Eigen::MatrixXd out(d, n1*n2); // Variant 1: int idx = 0; for (int c = 0; c != n2; c++) { for (int r = 0; r != n1; r++) { out.col(idx) = x1.col(r)  x2.col(c); idx += 1; } } // Variant 2: int idx = 0; for (int c = 0; c != n2; c++) { out.block(0, idx, d, n1) = x1.colwise()  x2.col(c); idx += n1; }

eigs() function in Matlab returns complex double instead of double
I have two symmetric matrices A and B with 1600*1600 dimension. A and B are double matrices and I need to use eigs() function in Matlab, I intend it to returns double output. But whenever I check matrix 'W', it is complex double.
[W,~] = eigs(A, B+ 1e3*eye(2*m), k, 'LM'); A = W(1:m, :); Att = W(m+1:end, :);
Do you know why it happens and how can I handle it?

How to plot multiple planes in Matlab in one figure using equations?
I have 4 planes i need to plot in one figure for my optimization course. The equations are:
 x=10000
 y=12000
 z=40000
 z=2*y
Also x,y,z have a nonnegativity condition so all the planes have to be positive. I know Matlab might not be able to use arrays that big so scaling down would be the solution, but i need an easy way to plot those planes in the same figure. Thank you.

A greyscale digital image can be defined as a two dimensional matrix containing 0’s
A greyscale digital image can be defined as a two dimensional matrix containing 0’s (representing black) and 1’s (representing white). Research the eye function. Hence create a 100x100 identity matrix and use imshow to plot a greyscale representation of the identity matrix. Now use for loops and if statements to add to the identity matrix the following white lines: • Add a horizontal line at rows 50 and 51. • Add a vertical line at columns 50 and 51. • Add a diagonal line from topright to bottom left.
so far this is what i've got: help(eye) eye(100,100) imshow(eye(100,100))
im just not sure how to use the for loops to get the horizontal, vertical and diagonal lines. can someone help?

SpaceTime Block Coding with Channel Estimation MIMO
I have error on this code：
SpaceTime Block Coding with Channel Estimation from MathWork.
Please can any one help me! i want to evaluate the performance of
mimoofdm
.frmLen = 100; % frame length maxNumErrs = 300; % maximum number of errors maxNumPackets = 3000; % maximum number of packets EbNo = 0:2:12; % Eb/No varying to 12 dB N = 2; % number of Tx antennas M = 2; % number of Rx antennas pLen = 8; % number of pilot symbols per frame W = hadamard(pLen); pilots = W(:, 1:N); % orthogonal set per transmit antenna % Create a comm.MIMOChannel System object to simulate the 2x2 spatially % independent flatfading Rayleigh channel chan = comm.MIMOChannel( ... 'MaximumDopplerShift', 0, ... 'SpatialCorrelationSpecification', 'None', ... 'NumTransmitAntennas', N, ... 'NumReceiveAntennas', M, ... 'PathGainsOutputPort', true); % Change the NumReceiveAntennas property value of the hAlamoutiDec System % object to M that is 2 release(ostbcComb); ostbcComb.NumReceiveAntennas = M; % Release the hAWGN2Rx System object release(awgn2Rx); % Set the global random stream for repeatability s = rng(55408); % Preallocate variables for speed HEst = zeros(frmLen, N, M); ber_Estimate = zeros(3,length(EbNo)); ber_Known = zeros(3,length(EbNo)); % Set up a figure for visualizing BER results fig = figure; grid on; ax = fig.CurrentAxes; hold(ax,'on'); ax.YScale = 'log'; xlim(ax,[EbNo(1), EbNo(end)]); ylim(ax,[1e4 1]); xlabel(ax,'Eb/No (dB)'); ylabel(ax,'BER'); fig.NumberTitle = 'off'; fig.Name = 'Orthogonal SpaceTime Block Coding'; fig.Renderer = 'zbuffer'; title(ax,'Alamouticoded 2x2 System'); set(fig,'DefaultLegendAutoUpdate','off'); fig.Position = figposition([41 50 25 30]); % Loop over several EbNo points for idx = 1:length(EbNo) reset(errorCalc1); reset(errorCalc2); awgn2Rx.EbNo = EbNo(idx); % Loop till the number of errors exceed 'maxNumErrs' % or the maximum number of packets have been simulated while (ber_Estimate(2,idx) < maxNumErrs) && ... (ber_Known(2,idx) < maxNumErrs) && ... (ber_Estimate(3,idx)/frmLen < maxNumPackets) % Generate data vector per frame data = randi([0 P1], frmLen, 1); % Modulate data modData = bpskMod(data); % Alamouti SpaceTime Block Encoder encData = ostbcEnc(modData); % Prepend pilot symbols for each frame txSig = [pilots; encData]; % Pass through the 2x2 channel reset(chan); [chanOut, H] = chan(txSig); % Add AWGN rxSig = awgn2Rx(chanOut); % Channel Estimation % For each link => N*M estimates HEst(1,:,:) = pilots(:,:).' * rxSig(1:pLen, :) / pLen; % assume held constant for the whole frame HEst = HEst(ones(frmLen, 1), :, :); % Combiner using estimated channel decDataEst = ostbcComb(rxSig(pLen+1:end,:), HEst); % Combiner using known channel decDataKnown = ostbcComb(rxSig(pLen+1:end,:), ... squeeze(H(pLen+1:end,:,:,:))); % ML Detector (minimum Euclidean distance) demodEst = bpskDemod(decDataEst); % estimated demodKnown = bpskDemod(decDataKnown); % known % Calculate and update BER for current EbNo value % for estimated channel ber_Estimate(:,idx) = errorCalc1(data, demodEst); % for known channel ber_Known(:,idx) = errorCalc2(data, demodKnown); end % end of FOR loop for numPackets % Plot results semilogy(ax,EbNo(1:idx), ber_Estimate(1,1:idx), 'ro'); semilogy(ax,EbNo(1:idx), ber_Known(1,1:idx), 'g*'); legend(ax,['Channel estimated with ' num2str(pLen) ' pilot symbols/frame'],... 'Known channel'); drawnow; end % end of for loop for EbNo % Perform curve fitting and replot the results fitBEREst = berfit(EbNo, ber_Estimate(1,:)); fitBERKnown = berfit(EbNo, ber_Known(1,:)); semilogy(ax,EbNo, fitBEREst, 'r', EbNo, fitBERKnown, 'g'); hold(ax,'off'); % Restore default stream rng(s)
error from matlab
Error using pvParse Property SpatialCorrelationSpecification does not exist for class comm.MIMOChannel. Error in matlab.system.SystemProp/parseInputs Error in matlab.system.SystemProp/setProperties Error in comm.MIMOChannel (line 517) setProperties(obj, nargin, varargin{:}); Error in fig_2 (line 14) chan = comm.MIMOChannel( ...
thanks Regards

Hyperlink causes compiled MATLAB application to crash
I have a compiled matlab application, which has a gui. This gui also contains a webpage within it, index.html. In the html, there is a hyperlink to a website. I want matlab to load the webpage in an external browser when this link is clicked. currently, this is the hyperlink I use:
<a href="matlab:web('http://www.google.com','browser')">Help</a>
However, when clicked, the compiled program crashes and closes immediately. This does NOT happen when I start the program from within matlab; in this case it works as expected (and wanted). The effect is only present when the application is compiled. Why is this? Is there any way to fix it?
EDIT: here is a a simple verifiable example, etc.
first the simple matlab code:
% Create a blank figure window f=figure('Name','Browser GUI Fail','Units','norm'); % Add the browser object com.mathworks.mlwidgets.html.HTMLRenderer.setUseWebRenderer(false); jObject = com.mathworks.mlwidgets.html.HTMLBrowserPanel; [browser,container] = javacomponent(jObject, [], f); set(container,'Units','normalized','Position',[0 0 1 1 ]); url=['file:/' which('index.html') ]; browser.setCurrentLocation(url);
second, the html file, index.html
<!DOCTYPE html> <html> <body> <p>stuff, anything at all <a href="matlab:web('http://www.google.com','browser')">Help</a> </p> </body> </html>
The link fails in the compiled version of the program. I am on Windows, and using 2014b.

How to set mwArray with user predefined data? Is it possible mix Matlab library compiler & mex runtimes?
I started working with Matlab production libraries: Matlab Coder and Matlab library Compiler. I have several questions
What is the difference between mxArray and mwArray? (answer below)
Is it possible to set mxArray with user predefined data? (answer below)
3. Is it possible to set mwArray with user predefined data?
4. Is it possible to run Matlab library compiler DLL from mex file?
I combined a matlab library compiler dll with matlab coder using
coder.ceval(...)
The first call to either
mlcInitializeApplication(..)
or
MY_MATLAB_LIBRARY_NAME_Initialize(..)
return false and any mwArray constructor throws an exception
Is there a problem mixing mex and mlc runtime libraries?
** btw  when I compiled the mex code to C++ everything worked.

mkl.dll: Not enough storage is available to process this command(Matlab/.Net C#)
We have a function in Matlab for which we have created Dll (for .Net) using Application compiler in Matlab. We have added this Dll to the main project where it is getting the call. At runtime when this function gets executes it throws an error
mkl.dll: Not enough storage is available to process this command
Function Details: 200 images as separate input and 4 other parameters so total it is 204 input parameter. the function returns 3dimensional array around 100k points.