You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: tooltipstring.m
    path of file: ./repos/spinw/swfiles/+swplot
    
    the code of the file until where you have to start completion: function string = tooltipstring(swObject,obj)
% generates tooltip text
% 
% ### Syntax
% 
% `swplot.tooltipstring(swObject,[])`
% 
% `swplot.tooltipstring(swObject,obj)`
%
% ### Description
% 
% `swplot.tooltipstring(swObject)` generates tooltip string from the data
% of a graphical object.
% 
% ### Input Arguments
% 
% `swObject`
% : Struct, that contains the object data that is clicked on.
% 
% `obj`
% : [spinw] object that provides data to the tooltip tex
    
function string = mat2str(M, format)
% converts matrix into string
%
% MAT2STR(mat, {format}) 
%
% The function converts an NxM matrix into a string with nice zeros, also
% works for matrices with symbolic values.
%
% Input:
%
% M         Two dimensional matrix. format Numerical precision for
%           sprintf function, 1x2 vector: [p1 p2]. It generates the format
%           %p1.p2f. Default is [6 3], optional.
%

if nargin == 1
    p1  = 6;
    p2  = 3;
else
    p1 = format(1);
    p2 = format(2);
end