annotate findFieldWidth.m @ 577:e45c9b56d50d feature/grids

Add an Empty grid class The need turned up for the flexural code when we may or may not have a grid for the open water and want to plot that solution. In case there is no open water we need an empty grid to plot the empty gridfunction against to avoid errors.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 07 Sep 2017 09:16:12 +0200
parents 30ae48efc7ae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
1 % Calculates the maximum field width needed width fprintf for a given format fmt for the values in A
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
2 % A = [1.13232 10.233 1.1];
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
3 % width = findFieldWidth('%.2f',A);
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
4 % Gives wdith = 5
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
5 function width = findFieldWidth(fmt, A)
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
6 width = 0;
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
7 for i = 1:numel(A)
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
8 elem = A(i);
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
9 if iscell(elem)
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
10 elem = elem{1};
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
11 end
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
12 str = sprintf(fmt,elem);
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
13 width = max(width,length(str));
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
14 end
30ae48efc7ae Added utility function findFiledWidth. Added function for calculating and saving solutions.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
15 end