How to print Value in next line of Table in App desiginer

Hello, I hope you are doing well. I have used the sprintf as follow But it does not go to the next file all character are in single row/line when I print it on Table in app designer
pred11= sprintf('\n Class 1 Butterfly Levels: %d\n\n\n Class 1 Butterfly DValue: [%s]\nMaximum Value of Butterfly:%d\nMinimum Value Butterfly :%d\n',...
T.Levels, join(string(unique(T.DValue)),' '), T.Dmaximum, T.Dminimum);

 Accepted Answer

use [ ] operator as below or try with for loop which always works as intended
pred11= sprintf('\n Class 1 Butterfly Levels: %d\n\n\n Class 1 Butterfly DValue: [%s]\nMaximum Value of Butterfly:%d\nMinimum Value Butterfly :%d\n',...
[T.Levels; join(string(unique(T.DValue)),' '); T.Dmaximum; T.Dminimum]);

22 Comments

@VBBV it gives error
Error using sprintf
Conversion to int64 from string is not possible.
try othwerwise with for loop
for k = 1:length(T.Levels)
% remaining code...
pred11= sprintf('\n Class 1 Butterfly Levels: %d\n\n\n Class 1 Butterfly DValue: [%s]\nMaximum Value of Butterfly:%d\nMinimum Value Butterfly :%d\n',...
T.Levels(k), join(string(unique(T.DValue(k))),' '), T.Dmaximum(k), T.Dminimum(k));
end
@VBBV Error using vertcat
Dimensions of arrays being concatenated are not consistent.
@VBBV please run it on the data i have upload and provide solution
i have updated the code above, can you check with updated code
if i run using data provided, it works fine, but your problem is something different i guess, its printing the data into a table in App designer. you may not need sprintf function, instead you can directly call the table variables using structure to print or display them in a table in App designer
load('print.mat')
for k = 1:length(T.Levels)
pred11= sprintf('\nClass 1 Butterfly Levels: %d\n\n\nClass 1 Butterfly DValue: [%s]\nMaximum Value of Butterfly:%d\nMinimum Value Butterfly :%d\n',...
T.Levels(k), join(string(unique(T.DValue(k))),' '), T.Dmaximum(k), T.Dminimum(k))
end
pred11 =
' Class 1 Butterfly Levels: 6 Class 1 Butterfly DValue: [80] Maximum Value of Butterfly:650 Minimum Value Butterfly :80 '
Here you can see it print in single row, No In next line/row
After testing in Matlab online, please make these changes, the below code works fine
load('print.mat')
vars = {'Levels','Dvalue','Dmaximum','Dminimum'};
T = table(T.Levels,unique(T.DValue),T.Dmaximum,T.Dminimum,'VariableNames',vars)
fig = uifigure
uit = uitable(fig,'Data',T)
@VBBV Not working, it just gives all values in array. No the print which i want
add one extra line shown in code below , hope this works
load('print.mat')
vars = {'Levels','Dvalue','Dmaximum','Dminimum'};
T = table(T.Levels,unique(T.DValue),T.Dmaximum,T.Dminimum,'VariableNames',vars)
T = rows2vars(splitvars(T)) % add this line
T = table(T.OriginalVariableNames,T.Var1,'VariableNames',{'Parameter','Value'}) % add this too
fig = uifigure
uit = uitable(fig,'Data',T)
@VBBV Not working, It is like this one
you can change the vars in my previous code as
vars = {'Class 1 Butterfly Levels','Class 1 Butterfly Dvalue','Maximum value of Butterfly','Minimum value of Butterfly'};
and after modification it will be
load('print.mat')
% this change below
vars = {'Class 1 Butterfly Levels','Class 1 Butterfly Dvalue','Maximum value of Butterfly','Minimum value of Butterfly'};
T = table(T.Levels,unique(T.DValue),T.Dmaximum,T.Dminimum,'VariableNames',vars)
T = rows2vars(splitvars(T)) % add this line
T = table(T.OriginalVariableNames,T.Var1,'VariableNames',{'Parameter','Value'}) % add this too
fig = uifigure
uit = uitable(fig,'Data',T)
@VBBV But it should in one row and multiple lines.
This is so many rows.
Since you are printing different variables in a table it will take table data as rows and columns and not as one single row. However if you are printing in a file it is possible as shown in my earlier comments
@VBBV We can print the data into multiple rows
like in this the data should be in four rows.
One for Levels
2nd for Dvalue
3rd for Dmaximum
4th for Dminimum
@Med Future, I cannot understand what the goal is. Please provide an illustration of what you'd like to accomplish.
@Adam Danz As you see above my code i printing the character on same line while i am applying \n in my code
I want to print the character in new line for example
We can print the data into multiple lines
like in this the data should be in four lines.
One for Levels
2nd for Dvalue
3rd for Dmaximum
4th for Dminimum
Where should these text appear? In the command window? In a table? A uitable? The goal is still unclear.
I see that VBBV has given you lots of solutions and that you reply with phrases like "not working", "so many rows". This is a sign that the volunteers are not clear what your goal is or that you are unsure of the goal.
Rather than us guessing at what you want, developing a solution for that guess, and then finding out that it's not exactly what you're looking for, please illustrate exactly what you want.
I'd be happy to provide one more solution if the goal is crystal clear.
Okay Let me explain this to you I want to print value in appdesigner Table.
I have the Table in print.mat file in which different field exist. I have write the following code, which gives character array. which is basically in single line
pred11= sprintf('\n Class 1 Butterfly Levels: %d\n\n\n Class 1 Butterfly DValue: [%s]\nMaximum Value of Butterfly:%d\nMinimum Value Butterfly :%d\n',...
T.Levels, join(string(unique(T.DValue)),' '), T.Dmaximum, T.Dminimum);
I want to print in multiple line in appdesigner table for example like the following
Class 1 Butterfly Levels: 6
Class 1 Butterfly DValue: [80 85 355 550 600 650]
Maximum Value of Butterfly:650
Minimum Value Butterfly :80
See snapshot below , if this is what you want
load('print.mat')
% this change below
vars = {'Class 1 Butterfly Levels','Class 1 Butterfly Dvalue','Maximum value of Butterfly','Minimum value of Butterfly'};
S = num2str(unique(T.DValue)) % convert the Dvalue to character
D = {vars{1},T.Levels;vars{2},S;vars{3},T.Dmaximum;vars{4},T.Dminimum};
fig = uifigure;
uit= uitable(fig);
uit.Data = D;
uit.Position = [71 61 500 233]; % modify the table size using its position property

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022a

Asked:

on 26 Dec 2022

Edited:

on 29 Dec 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!