Remove automatic display in octave - command-line

I want to convert java matrix to octave matrix. To that end, I use the function http://information-dynamics-toolkit.googlecode.com/svn/trunk/demos/octave/javaMatrixToOctave.m which works fine.
The only issue is that the line
octaveMatrix = tmp.ident(tmp);
prints on the command line the following text
[ (2 by 2) array of double ]
I would like to be able to prevent this to happen. But how?

Related

extra lines in command window output

I am very new to MATLAB and i am currently trying to learn how to import files in matlab and work on it. I am importing a "*.dat" file which contains a single column of floating point numbers[they are just filter coefficients I got from a c++ code] into an array in MATLAB. When I am displaying the output in command window the first line is always " 1.0e-03 * " followed by the contents of my file. I want to know what it means? When I check my workspace the array connects the correct number of inputs. My sample code and first few lines of output are below:
Code:-
clear; clc;
coeff = fopen('filterCoeff.dat');
A = fscanf(coeff, '%f');
A
fclose(coeff);
Output:-
A =
**1.0e-03 *** <===== What does this mean?
-0.170194000000000
0
0.404879000000000
0
-0.410347000000000
P.S: I found many options to read file eg. textscan, fscanf etc. Which one is the best to use?
It is a multiplier that applies to all the numbers displayed after that. It means that, for example, the last entry of A is not -0.410347 but -0.410347e-3, that is, -0.000410347.
I think it is is just Matlab's display number type. It means each of your results are scaled by that amount.
format longg
A
And see what it displays. Look at the docs for format for other options.

Matlab is printing comments and other contents of a script to command window

Below is a script in which I sum elements of a vector.
My problem here is that whenever I run the script, Matlab prints everything onto the command window. That is, it prints the comments, and everything else.
I only wanted to print the sum as an output, that is why I did not put ; after y = sum(x).
Can somebody help me prevent Matlab from printing the comments and contents of the script, except the ones I only want to print? Below is the script
%simple script
%this script sums the number of elements in a vector.
x = 1:2:10;
y = sum(x)
Here is the output in command window
Apparently echo on has been set in your MATLAB. You need to turn it off:
>> echo off

MatLab latex title doesn't work for powers (^)

In MatLab (R2015a), I want to style the title of my plots using latex.
This is working fine for some functions, but not if there's a power in the equation.
The below code works, and shows a formatted title to the right, and an unformatted title to the left.
It shows the warning:
Warning: Error updating Text.
String must have valid interpreter syntax: y = x^2
syms x y
eq = y == x^2;
subplot(1,2,1)
ezplot(eq)
title(latex(eq),'interpreter','latex')
eq = y == x+2;
subplot(1,2,2)
ezplot(eq)
title(latex(eq),'interpreter','latex')
EDIT:
I just found out I can get it to work by appending $ on both sides. But it seems weird that I would have to do this.
So this works:
title(strcat('$',latex(eq),'$'),'interpreter','latex')
Solution
The problem can be solved easily by adding $-signs before and after the generated LaTeX-expression. So you can change your «title-lines» to:
title(['$',latex(eq),'$'],'interpreter','latex')
An alternative is to use strcat as proposed in your question.
Explanation
Since you basically answered the question yourself already, I'm going to explain why it happened. Hopefully after reading this, it's no longer 'weird' behaviour. If you choose to use the LaTeX-interpreter in Matlab, you really get a LaTeX-interpreter. This means that the provided string must be valid LaTeX-syntax.
Using ^ outside a math-environment is considered invalid syntax because it is a reserved character in LaTeX. Some interpreters automatically add the $ before and after in this case, but throw a warning at the same time.
The output of the latex-function in Matlab is provided without the $-signs. This way you can combine outputs and concatenate if needed without creating a mess with $-signs.
To change to the math-environment in LaTeX you can use the already mentioned shortcut $...$. An alternative way is to use \begin{math} your_equation \end{math}. It produces the same result for your equations and can be used here for demonstration purposes. The following line would do the same job, but is a bit longer to write:
title(['\begin{math}',latex(eq),'\end{math}'],'interpreter','latex')
Now, the reason why only one of your equations is displayed correctly, lies in the invalid character ^ in y = x^2. Matlab then chooses interpreter none and therefore displays the string unformatted. The +-sign in y = x + 2 is valid outside a math-environment, so it gets displayed correctly (but is not interpreted in a math-environment).

Append legends. Whats wrong with my code?

I'm trying to add legends the plot when it adds a curve. I can't see whats wrong with my code, can someone please help? I'm using matlab r2015a on ubuntu.
x=1:5;
v=1:5;
plot(x,v)
[~,~,plots,str] = legend('1');
hold on
for i=4:10
pl=plot(x,v*i);
[~,~,plots,str]=legend([plots;pl],str,num2str(i))
end
when i run it i get:
plots =
1x2 Line array:
Line Line
str =
'1' '4'
Error using vertcat
Dimensions of matrices being
concatenated are not
consistent.
So its means it works the first lap but not the second.
As discussed in the comment, the way Matlab handles legends is different than in earlier releases; they are now legend objects.
In any case, to solve your problem, which is a dimension mismatch problem, you can simply concatenate vertically the outputs you get using the transpose operator, because Matlab returns a horizontal array of line and text objects whereas you want a vertical array. Therefore, using plots.' and pl.' works fine. Also, it's good practice not to use i as a loop counter since it represents the imaginary unit.
clear
clc
close all
x=1:5;
v=1:5;
plot(x,v)
[~,~,plots,str] = legend('1');
hold on
for k=4:10
pl=plot(x,v*k);
[LegendObject,~,plots,str]=legend([plots.';pl.'],str,num2str(k));
end
%// Use the legend object to modify its properties/location
set(LegendObject,'Location','NorthWest');
Output:

Avoid list being truncated by Matlab

Edit 1 - This question has been solved and it was due to a typo thanks to Floris for spotting this.
I have a one line matrix in Matlab which it is truncating and causing me to loose data.
My code reads:
[status,Vf_rpm_string] = system (fragment_velocity_string);
Vf_rpm_shape=regexprep(Vf_rpm_string,'\n',' ');
Vf_rpm_vector=str2num(Vf_rpm_string);
Vf_rpm= reshape(Vf_rpm_vector,[],1);
The code conducts a system command and stores the result, the result is a Matrix of numbers and sometimes the last line in the matrix has less columns than the previous lines. Matlab doesn't like this, as it does not know what to do with the empty few columns in the last line. So I have to remove the new line character from the results (\n) and replace it with a space.
This was working fine until the results from the system command were too large and so when I remove the new line character (\n) and replace it with a space creating a one line matrix it is too long for Matlab and it truncates it and I loose a lot of my data. So when I convert the returned data (which is returned as a string) to a number it gives me an empty matrix, then the reshape command is pointless at this point.
This is how it reads in Matlab:
20.65866342... Output truncated. Text exceeds maximum line length of 25,000 characters for Command Window display.
So the 20.65866342 is the last value before I start to loose data. I know it says it is too large for the command window but still the variable does not store all the data and it is lost.
Does anyone have any solutions to avoid this truncation?
Or does anyone want to suggest an alternative method for me to convert my data?
I am using Matlab 2012b and Windows 7
Thanks for your time.
Could the problem be that you strip the newlines, but the stripped string isn't the one you are parsing?
[status,Vf_rpm_string] = system (fragment_velocity_string);
Vf_rpm_shape=regexprep(Vf_rpm_string,'\n',' ');
Vf_rpm_vector=str2num(Vf_rpm_string);
Vf_rpm= reshape(Vf_rpm_vector,[],1);
That third line of code should be
Vf_rpm_vector=str2num(Vf_rpm_shape);
if I understand the logic of your code.