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);

 採用された回答

VBBV
VBBV 2022 年 12 月 26 日

0 投票

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 件のコメント

Med Future
Med Future 2022 年 12 月 26 日
@VBBV it gives error
Error using sprintf
Conversion to int64 from string is not possible.
VBBV
VBBV 2022 年 12 月 26 日
編集済み: VBBV 2022 年 12 月 26 日
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
Med Future
Med Future 2022 年 12 月 26 日
@VBBV Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Med Future
Med Future 2022 年 12 月 26 日
@VBBV please run it on the data i have upload and provide solution
VBBV
VBBV 2022 年 12 月 26 日
i have updated the code above, can you check with updated code
VBBV
VBBV 2022 年 12 月 26 日
編集済み: VBBV 2022 年 12 月 26 日
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 '
Med Future
Med Future 2022 年 12 月 26 日
Here you can see it print in single row, No In next line/row
VBBV
VBBV 2022 年 12 月 26 日
編集済み: VBBV 2022 年 12 月 26 日
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)
Med Future
Med Future 2022 年 12 月 26 日
@VBBV Not working, it just gives all values in array. No the print which i want
VBBV
VBBV 2022 年 12 月 26 日
編集済み: VBBV 2022 年 12 月 26 日
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)
Med Future
Med Future 2022 年 12 月 27 日
@VBBV Not working, It is like this one
VBBV
VBBV 2022 年 12 月 27 日
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
VBBV 2022 年 12 月 27 日
Med Future
Med Future 2022 年 12 月 27 日
@VBBV But it should in one row and multiple lines.
This is so many rows.
VBBV
VBBV 2022 年 12 月 27 日
編集済み: VBBV 2022 年 12 月 27 日
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
Med Future
Med Future 2022 年 12 月 27 日
@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
Adam Danz
Adam Danz 2022 年 12 月 27 日
@Med Future, I cannot understand what the goal is. Please provide an illustration of what you'd like to accomplish.
Med Future
Med Future 2022 年 12 月 28 日
@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
Adam Danz
Adam Danz 2022 年 12 月 28 日
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.
Med Future
Med Future 2022 年 12 月 29 日
編集済み: Adam Danz 2022 年 12 月 29 日
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
VBBV
VBBV 2022 年 12 月 29 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で App Building についてさらに検索

製品

リリース

R2022a

質問済み:

2022 年 12 月 26 日

編集済み:

2022 年 12 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by