add lines cell matlab

2 ビュー (過去 30 日間)
best16 programmer
best16 programmer 2016 年 11 月 24 日
コメント済み: best16 programmer 2016 年 11 月 24 日
i have two edit texts,they show the vectors :
1 1 1 1 and 1 -1 1 1
-1 1 1 1 -1 1 1 -1
how can i add the two first lines together and the two secondes lines together and the result is :
2 0 2 2
0 2 2 0

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 11 月 24 日
Presumably you have two multiline edit text controls such that when you call
get(handles.edit1,'String')
a cell array is returned. We can probably simulate this with
text1Array = [cellstr('1 1 1 1') ; cellstr('-1 1 1 1')];
which returns a cell array with two elements where each element is a string. We can then want to convert each string into an array of numbers so that we can add the lines together. If we assume just two lines of four elements each then
arraySum1 = str2num(text1Array{1,:}) + str2num(text1Array{2,:});
which returns
arraySum1 =
0 2 2 2
which is the sum of the first two lines. You can then repeat this for the other edit text control.
text2Array = [cellstr('1 -1 1 1') ; cellstr('-1 1 1 -1')];
arraySum2 = str2num(text2Array{1,:}) + str2num(text2Array{2,:});
and concatenate the two and convert to a string as
concatenatedArraysAsString = num2str([arraySum1 arraySum2]);
where
concatenatedArraysAsString =
0 2 2 2 0 0 2 0
The answer is different from yours so perhaps I've misunderstood your rules.
  2 件のコメント
Geoff Hayes
Geoff Hayes 2016 年 11 月 24 日
Huh. Looks like you changed your question from when I started writing an answer for it....
best16 programmer
best16 programmer 2016 年 11 月 24 日
thank you,i just want to say that these vector belong to different edit texts,so the first vector in the first edit text should be added to the first vector in the second edit text and sum will be displayed in another edit text.do you have some solutions. thanks for advence

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

その他の回答 (1 件)

KSSV
KSSV 2016 年 11 月 24 日
Let A and B be your matrices.
iwant = A+B;
Best programmer please read basics of matlab.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by